snacktime
2006-Jul-23 23:49 UTC
[Mongrel] Persistant database connections with custom handler
I''ve been looking at using mongrel for a lightweight web service I want to do in ruby. Everything looks pretty simple, but I''m wondering what would be a good way to persist database connections? Is there an easy way to use activerecord in a custom handler and use it''s connection pooling? Chris
Zed Shaw
2006-Jul-24 05:45 UTC
[Mongrel] Persistant database connections with custom handler
On Sun, 2006-07-23 at 16:49 -0700, snacktime wrote:> I''ve been looking at using mongrel for a lightweight web service I > want to do in ruby. Everything looks pretty simple, but I''m wondering > what would be a good way to persist database connections? Is there an > easy way to use activerecord in a custom handler and use it''s > connection pooling?The mongrel handlers are registered as one object per each URI you put in the classifier (each time do "uri ''/'', BlahHandler.new). This means that any class variables are persistent between connections. Also means you needs to thread lock those real quick if the connector isn''t thread safe. It''s doable but don''t expect it to be ultra nice. Only do this if you really need the ultra speed and test the results periodically to see if it actually is faster than a rails version. You most likely won''t get greater performance off a Mongrel only handler unless you also do some good caching. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/ http://www.railsmachine.com/ -- Need Mongrel support?