Home arrow Ruby-on-Rails arrow Page 4 - Load Balancing Databases with Rails
RUBY-ON-RAILS

Load Balancing Databases with Rails


In this conclusion to a five-part series on databases and Ruby-on-Rails, you'll learn how a number of databases handle load balancing and high availability issues. This article is excerpted from chapter four of the book Advanced Rails, written by Brad Ediger (O'Reilly; ISBN: 0596510322).Copyright © 2008 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

Author Info:
By: O'Reilly Media
Rating: 3 stars3 stars3 stars3 stars3 stars / 2
February 04, 2010
TABLE OF CONTENTS:
  1. · Load Balancing Databases with Rails
  2. · PostgreSQL
  3. · LDAP
  4. · Authenticating with LDAP

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Load Balancing Databases with Rails - Authenticating with LDAP
(Page 4 of 4 )

One of the most common reasons for using LDAP is to integrate into an existing authentication structure. If an LDAP server is provided for a Windows domain, this will allow the web application to authenticate users against that domain rather than maintaining its own user models separately.

Set up the ldap.yml file as described previously (without specifyinga password), but do not bind to the LDAP server from environment.rb. We will perform the bind as part of the authentication process. The following code is adapted from the Rails wiki:*

  class LdapUser < ActiveLDAP::Base
    ldap_mapping :prefix => (LDAP prefix for your users)

    LDAP_PATH = File.join(RAILS_ROOT,"config","ldap.yml")
    LDAP_CONFIG = YAML.load(File.read(ldap_path))[RAILS_ENV]

    def self.authenticate username, password
      begin 

       ActiveLDAP::Base.establish_connection(config.merge(
         :bind_format => "uid=#{username},cn=users,dc=mycompany,dc=com",
         :password => password,
         :allow_anonymous => false

      ))
      ActiveLDAP::Base.close
      return true

      rescue ActiveLDAP::AuthenticationError
        return false
      end
    end
  end

Authentication is then very simple:

  LdapUser.authenticate "my_username", "password" # => true or false

Further Reading

Chris Date's Database in Depth (OReilly) is a very accessible introduction to relational theory aimed at software developers who are experienced in the use of relational databases. It reintroduces readers into the technical foundations behind the relational model.

Theo Schlossnagle's Scalable Internet Architectures (Sams) is a short but comprehensive treatment of ways to accomplish scalability (both high availability and load balancing are covered); it covers ground from the smallest two-server failover cluster up to global server load balancing.

Both the MySQL manual (http://dev.mysql.com/doc/) and the PostgreSQL manual (http://www.postgresql.org/docs/) have a wealth of information about general database topics, as well as specific information pertaining to the use of those DBMSs.

 


* Informally, DBMSs are often referred to as “databases." Consistent with industry practices, in this book "database management system" refers to the software package or installation thereof, while "database" refers to the actual data set being managed.

 

* Technically pronounced "post-gres-Q-L," and usually just called "Postgres." This is a contender for the least intuitive name in computing today. It has its roots in PostgreSQL’s long-ago predecessor, Postgres, which did not support SQL.

† For a detailed look at how Postgres handles concurrency, including a summary of the potential problems and how Postgres handles them, see the documentation at http://www.postgresql.org/docs/8.2/interactive/
transaction-iso.html.

For a detailed look at how Postgres handles concurrency, including a summary of the potential problems and how Postgres handles them, see the documentation at

* ACID stands for Atomic, Consistent, Isolated, and Durable, which are necessary properties for transactional integrity within a database. See http://en.wikipedia.org/wiki/ACID for a full definition and explanation.

† Instructions are at http://wiki.rubyonrails.org/rails/pages/ HowtoConnectToMicrosoftSQLServerFromRailsOnLinux;
FreeTDS is available from
http://www.freetds.org/.

http://rubyforge.org/projects/ruby-oci8/

* Short for "byte array."

† Assuming fairly uniform binary data, the BYTEA quoting rules lead to an average expansion ratio of 1:2.9.

‡ The size is defined in LOBLKSIZE. It defaults to 2 KB.

* http://celebnamer.celebworld.ws/stuff/ mod_xsendfile/

* http://cleanair.highgroove.com/articles/ 2006/10/03/mini-file-uploads

* http://www.martinfowler.com/bliki/ DatabaseStyles.html

* I would probably keep that one at the application level, because it contains the business rule that no employee’s salary is zero. However, "an employee’s salary must be non-negative" would most likely be an
integrity constraint, as it is nearly inconceivable that you would "pay" an employee a negative salary.

http://drysql.rubyforge.org/

* Pronounced "mem-cache-dee," for "memory cache daemon." Available from http://danga.com/memcached/.

* http://wiki.rubyonrails.org/rails/pages/ HowtoAuthenticateViaLdap

 


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
RUBY-ON-RAILS ARTICLES

- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form
- Ruby on Rails Templates and Layouts
- Action Pack Controller Creation
- Writing an Action Pack Controller

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials