Pearware Blog : Archives for November 2006 http://blog.pearware.org/articles/2006/11.rss en-us 40 agile web development Switched to pure ruby ldap library <p>I <a href="http://blog.pearware.org/2005/5/23/ldap-authentication-in-rails">wrote an article awhile back</a> about using the Ruby/LDAP library to handle <span class="caps">LDAP</span> authentication in Ruby on Rails. I just finished swapping out the <span class="caps">LDAP</span> client library in that application from <a href="http://ruby-ldap.sourceforge.net/">Ruby/LDAP</a> to <a href="http://rubyforge.org/projects/net-ldap/">ruby-net-ldap</a>. The problems with Ruby/LDAP are that it isn&#8217;t a <span class="caps">GEM</span>, so installation is a bit more difficult, and it relies on a common <span class="caps">LDAP</span> library, like OpenLDAP, to already be installed on the system. The ruby-net-ldap library is written in pure Ruby, so no other library needs to be installed on the system.</p> <p>Here is the new code that performs the authentication:</p> <div class="typocode"><pre><code class="typocode_default ">require &quot;net/ldap&quot; class User &lt; ActiveRecord::Base def self.authenticate(login, password, host, port) if login.to_s.length &gt; 0 and password.to_s.length &gt; 0 ldap = Net::LDAP.new ldap.host = host ldap.port = port ldap.auth = &quot;cn=#{login},cn=users,o=xyz...&quot;, password if ldap.bin return find(:first, :conditions =&gt; ['username=?', login]) else return false end end end end</code></pre></div> Mon, 20 Nov 2006 13:58:00 -0600 urn:uuid:2a0d0e66-c586-41cc-bde8-f30b0a4dc58a http://blog.pearware.org/articles/2006/11/20/switched-to-pure-ruby-ldap-library#comments ruby rails ruby net ldap rails authentication http://blog.pearware.org/articles/2006/11/20/switched-to-pure-ruby-ldap-library ActiveMailer email performance on site5 <p>The site I am working on, <a href="http://www.realidaho.com">RealIdaho.com</a>, is hosted by <a href="http://www.site5.com">site5</a>. There are some forms that, when filled out by the user, send confirmation emails to the user, to us internally, and to the realtor&#8217;s cellphone. We started getting some reports that the confirmation page wouldn&#8217;t come up, and users were resubmitting the form many times. I discovered a few things while investigating that may be useful to others.</p> <p>The first thing I noticed, is that the page would timeout after 15 seconds and just return a blank page. Not very friendly, and definitely explains why the users were unsure that the form was submitted properly. The site however continued to process the request, and eventually got all the emails out. I contacted the site5 support team and asked the 1) why is the page timing out after only 15 seconds, and 2) why was sending email so slow.</p> <p>Here&#8217;s the answer I got for item 1:</p> <div style="width: 90%; margin: auto; font-style: italic;"> &#8220;Changing the timeout would affect the global settings for apache. This results in a significant increase in the number of open connections that apache has and degrades server performance. I can ask about this but I don&#8217;t think it will be possible to increase the timeout.&#8221; </div> <p>While I understand their reasoning, 15 seconds seems awfully short. I believe the default for apache is 5 minutes. Hopefully, they&#8217;ll consider increasing that amount at least to 30-60 seconds. While I never want a page that takes more than 5 seconds, I&#8217;m sure we&#8217;ll have some pages that do take longer, especially ones that need to communicate with external systems.</p> <p>Regarding number 2, the support technician suggested using sendmail directly instead of sending email over <span class="caps">SMTP</span>, as that should be much faster. So, I went into <span class="caps">RAILS</span>_ROOT/config/environments/production.rb and added the following line:</p> <p>ActiveMailer::Base.delivery_method = :sendmail</p> <p>Here are the performance numbers:</p> <p>Previous method (SMTP):</p> <p>Sending Mail to user (25.22760)<br/> Sending Mail to internal (31.11207)<br/> Sending Mail notification (20.70688)<br/></p> <p>Current method (Sendmail):</p> <p>Sending Mail to user (0.16841)<br/> Sending Mail to internal (0.28479)<br/> Sending Mail notification (0.24701)<br/></p> <p>Wow, that&#8217;s quite a difference! When I tested the form submission, the confirmation page appeared almost immediately. Now that&#8217;s more like it. Now I just need to see about increasing the timeout.</p> Thu, 09 Nov 2006 13:52:00 -0600 urn:uuid:8ece63ce-6a03-48d3-8e90-5b32d72749a0 http://blog.pearware.org/articles/2006/11/09/activemailer-email-performance-on-site5#comments ruby rails rails ActiveMailer sendmail smtp site5 performance http://blog.pearware.org/articles/2006/11/09/activemailer-email-performance-on-site5