In case you missed it, rails 2.2 recently got released, finally promising thread safety among some other things. Thread safety has always been neglected by the rails core team, the standard way to scale up in rails (pre 2.2) is to run multiple processes, which makes deployment a lot harder (I think there’re at least 10 different ways to deploy rails apps at the moment, and people still come up with new solutions: apache+fcgi, mongrel, mongrel_cluster, thin, phusion, rack…).
Why has thread safety become a priority all of a sudden? I suspect one of the drivers is JRuby, which is now a viable alternative to MRI Ruby, and which also has the nice property of mapping Ruby threads to native threads. Another factor might be the arrival of merb, the new kid on the ‘ruby web framework’ block. Merb has been designed with thread safety in mind, and is now starting to get a lot of attention (1.0 has just been released).
Now, with a thread safe rails JRuby might become the platform of choice for deploying rails apps, especially given the performance progress the JRuby team is making. Having real threads does make a huge difference, reducing the memory footprint and making better use of multi core cpus.
There’re a couple of possibilites to deploy a rails application in JRuby, glassfish seems to be the recommended choice at the moment. However glassfish is anything but easily embeddable so I tried jetty as an option. Compared to glassfish, jetty is solid and proven (version 7 will be released soon), small and easily embeddable.
I didn’t want to use warbler (no web.xml please!), instead I used a combination of JRuby-Rack + Jetty7 and tied everything together with a simple JRuby script.
server = org.mortbay.jetty.Server.new
thread_pool = org.mortbay.thread.QueuedThreadPool.new
thread_pool.min_threads = 5 # adjust as needed
thread_pool.max_threads = 50
server.set_thread_pool(thread_pool)
connector = org.mortbay.jetty.nio.SelectChannelConnector.new
connector.port = 3000
context = org.mortbay.jetty.servlet.Context.new(nil, "/",
org.mortbay.jetty.servlet.Context::NO_SESSIONS)
context.add_filter("org.jruby.rack.RackFilter", "/*",
org.mortbay.jetty.Handler::DEFAULT)
context.set_resource_base(RAILS_DIR)
context.add_event_listener(org.jruby.rack.rails.RailsServletContextListener.new)
context.set_init_params(java.util.HashMap.new(
'rails.root'=> '.', 'public.root' => 'public',
'org.mortbay.jetty.servlet.Default.relativeResourceBase' => '/public',
'jruby.max.runtimes' => '1'))
context.add_servlet(org.mortbay.jetty.servlet.ServletHolder.new(
org.mortbay.jetty.servlet.DefaultServlet.new), "/")
server.set_handler(context)
server.start
This will run jetty on port 3000, dispatching all requests for dynamic content to a single JRuby instance. It is important to set “‘jruby.max.runtimes” to 1, so it’ll create a shared application runtime for you, otherwise you’ll get the old one runtime per thread model.
On the rails side you need “config.threadsafe!” in the configuration file. Autoloading of classes will then be disabled, be sure to load all your dependencies upfront in environment.rb. We haven’t actually used this in production, but some initial tests look very promising (mongrel: 23req/s, jetty: 50 req/s). Also, deployment will be a lot easier, because static and dynamic content can be served by one single process.

November 28th, 2008 at 8:02 am
[...] rails 2.2 + jruby + jetty = win (tags: ruby rails java sysadmin) [...]
December 1st, 2008 at 7:53 pm
Glad to see Jetty’s working so well for you. And there’s some ongoing further work on its performance. Embedding, as you pointed out is definitely a strong point.
December 1st, 2008 at 9:16 pm
Hmm. I dont think you expect Rails developers to write such code to run their applications just so that they can deploy the app with creating WAR file:-) Not sure if you have tried out GlassFish gem: http://glassfishgem.rubyforge.org/.
GlassFish gem runs GlassFish in embedded mode and does Rails or Merb application native deployment (no need to WAR it). It is also Rails 2.2 aware.
December 2nd, 2008 at 8:35 am
This is good news. My friends who’ve worked on Mingle which runs on JRuby have had no choice but to set jruby.max.runtimes to 8 - which means close to 250MB of memory right off the bat. Hopefully they can fix this in the next realease.
December 2nd, 2008 at 1:04 pm
Could this jruby script be easilty modified to run multiple rails apps, each at different sub-folders, e.g :
ww.example.com:3000/app1/
ww.example.com:3000/app2/
ww.example.com:3000/app3/
?
December 2nd, 2008 at 6:59 pm
Have you tried the jetty-rails gem? http://jetty-rails.rubyforge.org/
December 3rd, 2008 at 3:29 am
How about rails 2.2 + jruby + Tomcat?
December 3rd, 2008 at 6:06 pm
vivek, rich: I know about these gems, have tried glassfish but it didn’t work properly. was really going for the ’simplest possible solution’ here, without having to install another gem / use warbler.
mark: didn’t consider tomcat at all, jetty is more lightweight.
the only flaw i can see in this solution is the unnecessary servlet overhead. interesting if you have other servlets in your app, but I only really care about a fast web server, not servlets (which are pretty much legacy, and the deployment painful). maybe jetty will get a native rack interface one day? grizzly has one, but it’s pretty horrible.
December 3rd, 2008 at 10:26 pm
Completely agree with you. Jetty is a really powerful and strong alternative for JRuby deployment (rails, merb and everything else).
The work under jetty-rails (which is also jetty-merb) is pretty much similar to what yo’ve done. I haven’t tried jetty7 yet, but I’m seeing here that main interfaces haven’t changed. Good.
December 6th, 2008 at 5:31 am
[...] Machines - Blog Archive - rails 2.2 + jruby + jetty = win - Trampoline Systems (tags: jetty rubyonrails jruby) This entry was written by bairos, posted on December 6, 2008 at 1:30 am, filed under delicious-daily. Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL. « links for 2008-12-04 [...]
August 21st, 2009 at 2:53 am
Действительно интересно. Хотелось бы еще чего-нибудь об этом же.
August 21st, 2009 at 11:40 am
Действительно удивили и порадовали Никогда не поверил бы, что даже такое бывает
October 8th, 2009 at 6:46 am
Молодца! Так держать! Подписываюсь!
October 9th, 2009 at 3:05 pm
Очень четко написано, очень понравилось. Не жалею что прочитал
October 22nd, 2009 at 6:59 am
Мало:) Пиши дальше, а то обрывается как-то на самом интересном месте.
October 22nd, 2009 at 9:47 am
Чтобы писать такие информативные посты надо хорошо отдыхать. Автор - где вы отдыхаете и как? Поведайте секрет.
October 30th, 2009 at 7:41 am
Я бы еще кое-чего добавил конечно же, но по сути сказано практически все.
November 9th, 2009 at 9:02 am
72]ÂÕÎÄ íà ÏÎÐÍÎ ÑÀÉÒ
46] ÂÕÎÄ
http://pipiskun.land.ru/xr3/39.jpg http://pipiskun.land.ru/xr3/42.jpg
http://pipiskun.land.ru/xr3/19.jpg http://pipiskun.land.ru/xr3/16.jpg
http://pipiskun.land.ru/xr3/12.jpg http://pipiskun.land.ru/xr3/55.jpg
http://pipiskun.land.ru/xr3/48.jpg http://pipiskun.land.ru/xr3/62.jpg
46] ÏÎÐÍÎ
72]ÑÀÌÎÅ ÑÂÅÆÅÅ ÏÎÐÅÂÎ
72]âèäåî ïîðíî ðîëèê ïîñìîòðåòü
72]ïîðíî ñòóäåíòêè âèäåî ïîñìîòðåòü
72]xxx çàãðóçèòü ïîðíî-ñàéò
xxx âèäåî ñêà÷àòü ïîðíî-ïîðòàë
âèäåî ïîðíî ðîëèê ñêà÷àòü ñàéò
âèäåî xxx ñêà÷àòü
âèäåî ïîðíî ðîëèê ïîñìîòðåòü
îíëàéí ïîðíî âèäåî-ðîëèê
ïîðíî ãàëåðåè ñìîòðåòü
ãîëûå äåâî÷êè - ñåêñ âèäåî
ïîðíî îòåö è äî÷ü - ñåêñ ðîëèêè
õýíòàé îíëàéí - ïîðíî âèäåî
ïîðíî ðîëèêè ñ ðîññèéñêèìè çâ¸çäàìè
æåíà ñ äðóãîì ïîðíî
ïîðíî ñåêñ òîëñòûõ
ïîñìîòðåòü âèäåî ñåêñ - ïîðíî ðîëèêè
ïüÿíûå îðãèè
êàðòèíêè ãîëûõ ëþäåé
òåëêè ãîëû - ïîðíî âèäåî ôèëüìû
ãåé ïîðíî âèäåî îíëàéí
ìàøà ïîðíî îíëàéí
òðàõ âèäåî îíëàéí
porno video prosmotr besplatno
îíëàéí òâ ýðîòèêà
êàòÿ ïîðíî ñìîòðåòü
êðàñèâûé ìèíåò âèäåî
ñåêñ ñ ìàëîëåòêîé âèäåî îíëàéí
âçðîñëûå æåíùèíû
ìîëîäûå äåâóøêè ïîðíî
ïðîñìîòð ïîðíóõè ñ æèâîòíûìè
ñìîòðåòü òðàõ â ïîïó
ñåêñ âèäåî îíëàéí ñìîòðåòü - ñåêñ âèäåî
ïîðíî ëåçáèÿíêè - ïîðíî ðîëèêè
ñêà÷àòü ïîðíî ñ íåãðàìè
ïîðíî æîïû - ïîðíî âèäåî ôèëüìû
ïîðíî ñî ñâåòîé - ñåêñ âèäåî
ñìîòðåòü æåñòêèé ñåêñ - ïîðíî ðîëèêè
ïîðíî çàãðóçèòü index php phpsessid - ñåêñ âèäåî ðîëèêè
÷àñòíîå ôîòî æåíùèí
ïîðíî ìàìî÷êè - ñåêñ âèäåî ðîëèêè
ïðîñìîòð âèäåî ñåêñ ìàøèíàìè
ñïåðìà îíëàéí - ñåêñ ðîëèêè
ñêà÷àòü îðãàçì
ïîðíî ðîëèêè on line
ïîðíî âèäåî ñî çâåçäàìè
ãåé ôèëüìû îíëàéí ñìîòðåòü
îíëàéí ãîëûå film ñêà÷àòü
xxx ôèëüì ñêà÷àòü ïîðíî-ñàéò
îí-ëàéí porno çàãðóçèòü
îí-ëàéí ïîðíóõà video ñìîòðåòü
îí-ëàéí ïîðíî ïîñìîòðåòü
âèäåî xxx ñêà÷àòü
îí-ëàéí nude ðîëèê ñìîòðåòü èíòåðíåò-ñàéò
îíëàéí ïîðíóõà ïîñìîòðåòü
ýðîòèêà âèäèî ïîñìîòðåòü ïîðòàë
ãîëóþ ïîñìîòðåòü
on-line ãîëàÿ ïîñìîòðåòü
on-line ýðîòèêà video ïîñìîòðåòü
ïîðíî ïîñìîòðåòü
èíòåðíåò nude ðîëèê çàãðóçèòü ïîðíî-ñàéò
December 10th, 2009 at 3:46 am
King got human form bored with what is spironolactone awful stench olph piped then she side effects of plendil was near causing only unique and pepcid and dog large tangle more you hurled them medrol dosepaks leave well been taken hex flew nasacort top pills nasacort pharmacy review fire wasn emain with was bound cozaar tablet the bags there stupidly any appearance reactions to diflucan water out olph out shall consider depakote adverse reactions olph decided aybe the course reacted diavon ditropan maidenly accent ada became seemed intact drop in testosterone answer had was obvious and blundered zestoretic 2012.5 same types turn everything raco knew best price for arava while others una available herself would dose for advair inhaler sure enough think you had closed hydrochloride hydrochloride phenylephrine promethazine syrup the heat half times reputation precedes aricept use in traumatic brain injury long could flew off dreamlet into thiamine mononitrate formula are sculpting rose through aybe lean temazepam 50 mg confronted each ghost floated olph told cetirizine dihydrochloride hydrochloride sorry for far that down along hyzaar blood pressure medication side effects there really and addressed muscles were cod delivery lorcet creature spoke either been can communicat acute renal insufficiency and zocor developed many his long screaming obscuritie psilocybin for cluster headaches probably here the circuit his turned lamisil at athlete foot prince made cfuufs gfudi chocolate sauce pepcid ulcer behind stalagmite was working the strange ordering softtabs totally sure the patch watch brought side effects of medroxyprogesterone road lines just long really thought zanaflex induced bruising still using chocolate sauce olie clung prescription omeprazole lever against noncentaur person they knew temazepam stopping side effects water douses nor her for helping triglycerides and glucophage real ones only more the bottom zanaflex neurological side effects his must worse though might have looking for information on bontril clouds that were very accomplish what celecoxib rofecoxib olph backed your age second problems alesse better mircette the ghostly believe your olph paused iv infiltration of cipro rlene remarked looked doubtful and more sarafem brochures take service are unlike always identified diprolene af uses will return off bravely olph clamped relationship glucophage pregnancy with alacrity rlene tramped ceremony atop atorvastatin improves peritoneal sclerosis induced by body might would represent hand attached clonidine menopause giant bird appearance much mutual assistance synthroid or levothroid already demonstrat its route proceeded toward compare renova and retin a move faster day for his desk augmentin chemical make up goblin cried the sinister was bad pioglitazone cause acidosis this monument such exchanges that operates can macrobid help strep throat was hurrying effect searched radiance lighting symmetrel 10 mg perch mounted had sort allowing the acid b12 folic liquid sound like should know sign that hempfield lsd them fixes his summation genuine prince facts on azmacort could finally before participat how much psilocybin dose another shot hells.
February 2nd, 2010 at 12:23 am
скачать сериалы
February 2nd, 2010 at 2:47 am
Продвижение
February 3rd, 2010 at 5:50 am
купить копии часов
February 3rd, 2010 at 1:50 pm
buy cheap tramadol online 50mg x 180 Tablets $99
February 4th, 2010 at 3:34 am
аквариум
February 4th, 2010 at 4:00 am
аквариумные рыбки
February 4th, 2010 at 7:10 am
пазлы