[Mongrel] OptimizedMutex for Mongrel

Ezra Zygmuntowicz ezmobius at gmail.com
Wed Nov 8 20:04:40 EST 2006


Hey Zed-

	I had a user with an app that was leaking memory with mongrel but  
not lighty/fcgi. I have been doing anything I can to track it down. I  
already did the Mutex patch to use unshitf and pop instead of shift  
and push and it didn't really help much. The mem leak only really  
shows up when you use the wsess option to httperf.

	The other day I saw a ruby C extension that Mentalguy built called  
optimized_locking. It has an OptimizedMutex class that is written in  
C. Its actually pretty small amount of C code and fairly easy to  
understand.

	Anyway, long story short, I patch the latest mongrel trunk and added  
this optimized_locking.c in as another C extension that gets built  
when you make the gem. It has helped quite a bit with the mem leak  
and seems to have better performance then Sync. I'm not suggesting  
this is needed in core mongrel but I thought I would share with you  
anyway to see what you think. I am attaching a gem built from svn  
trunk mongrel with the new OptimizedMutex C extension built it. I  
only used the OptimizedMutex for the rails handler so thats all that  
is patched in this gem. Play around with it and let me know if you  
can tell the difference.

	I have been using the same OptimizedMutex in Merb and it hasn't  
caused any issues yet. In fact it is measurably faster then the  
normal Mutex or Sync, even if only by a little. But it has pretty  
flatline memory consumption

	Installing the gem will build the optimized_locking c extension  
after it builds http11.

Grab it here:
http://brainspl.at/mongrel-c-mutex-0.3.14.gem.zip


	If anyone has any leaky apps and they want to try this out then  
please measure before and after and let me know the results.
	
Cheers-
-- Ezra Zygmuntowicz 
-- Lead Rails Evangelist
-- ez at engineyard.com
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)






More information about the Mongrel-users mailing list