Puma, a fast concurrent web server for Ruby
puma.io
puma.io
[1] http://blog.steveklabnik.com/posts/2013-02-24-using-puma-on-...
[2] http://www.subelsky.com/2012/10/setting-up-puma-rails-on-her...
It is not the first time I'm using JRuby and Puma, I must say I'm pretty happy with it.
I had enough with the official documentation, just tweaking the DB pool to fit in the Rediscloud free version constraints. [1]
https://devcenter.heroku.com/articles/concurrency-and-databa...
[0]: You'll need to download JCE 6 Extensions to get Puma, JRuby 1.7.4 and Rails 4 running in development: http://www.oracle.com/technetwork/java/javase/downloads/jce-...
[1]: Rediscloud free version gives you 10 connections.
I have looked at the source, and it appears a thread pool will listen to incoming requests, and pass them to a reactor then move on to handle more requests. Another thread polls the sockets and writes the data to the response stream when ready. [Note: this all may be completely wrong!]
If the way the server works as above is correct, does it mean it's possible to achieve event-loop-based levels of concurrent connections along with good old CPU concurrency as well?
What you said is basically correct. And yes, it is possible to combine event loops with threads in the way you described to get CPU concurrency as well. Whether it is actually helpful depends on the use case. The Phusion Passenger core is evented (similar to Nginx and Node.js) since version 4.0. We considered a multithreaded-evented architecture as well, but it turned out to be less beneficial than we hoped because the applications themselves use plenty of CPU already, and because we rely on shared in-memory state for proper load balancing between processes, thus having a source of contention. In the end, the single-threaded evented architecture in Phusion Passenger turned out to be more than enough.
The other component is the Ruby application process. I believe you are talking about this component.
Concurrency on the Ruby application process side is handled using two strategies:
1. Multiprocessing. 1 process per concurrent connection, with a buffering layer. This is architecturally the same as how Unicorn works when behind an Nginx reverse proxy.
2. Multithreading. 1 thread per concurrent connection, possibly with multiple processes. This is architecturally similar to Puma, though not entirely the same. It should be noted that multithreading support is available in the Enterprise version only.
I'm not affiliated with the author, but this was such a nice book to get an intro to webservers and their architectures/tradeoffs from.
Really fueled my love of sockets :)
But installing it as a module still seems to be the recommended method, so I can see still see why it isn't included in a list of servers that are meant to be proxied to.
I mean, this is not new at all, there is no major version that was released AFAIK...
This is great to share that though, just curious why it's on HN today? :)
Edit: typo fix.
I ran a the search and found the previous:
A modern, concurrent web server for ruby (puma.io)
16 points by kachhalimbu 1 year ago | 2 comments | cached[1] https://github.com/puma/puma#built-for-speed--concurrency
[2] http://docs.pylonsproject.org/projects/waitress/en/latest/de...
Edit: someone created an issue asking for contributors: https://github.com/TechEmpower/FrameworkBenchmarks/issues/45...
p.s. We are also hiring Ruby, and iOS folks. Contact information is in my profile.
We've recently written a comprehensive comparison between Puma and Phusion Passenger, which you can read here: https://github.com/phusion/passenger/wiki/Puma-vs-Phusion-Pa... The comparison covers things like concurrency models, I/O models, security, clustering, multi-app support, documentation, memory usage, performance and more. Although the comparison is between Puma and Phusion Passenger, a lot of the points are relevant to a Unicorn-Puma comparison as well.
I find it in poor taste come into a semi-related post and repeatedly spam links to your product over and over...
Since Passenger is by now pretty much the default way to run a Ruby stack I don't think any one here doesn't know who they are and so they really do not need to spam. They are just contributing to the discussion and I appreciate that.
One thing that some people don't know about Phusion Passenger is that it is versatile. Phusion Passenger Standalone is a mode, specifically designed to be dropped behind Nginx, just like Thin/Unicorn/Puma. That is a good alternative if you don't like the Apache/Nginx integrated modes.
But I see your point, and I'll keep it in mind. If I can edit my other posts I would remove some links but unfortunate HN has already frozen them.
We didn't have a great experience with passenger, it does seem bloated and we decided to move away from apache to nginx for similar reasons.
Tldr; We've been very happy with our move from passenger to puma.
But in our experience the app server is rarely the cause of such problems. Most people who complained about bloat in Unicorn/Puma/Passenger eventually discovered that it was a problem at the application level after all.
We'd be happy to help you with your issues if you can tell us more.
Passenger-free is a deliberately crippled demo-version. If someone wants to use passenger in production they will have to pay $50 USD per year, per server for it. And you know that very well.
The 'free' passenger drops requests and serves 502 errors to the users during every single deploy.
That's equivalent to popping up shareware nag-screens into my face at random intervals. Except phusion passenger doesn't nag me, it nags my customers.
You call the avoidance of these errors a 'feature' ('rolling restarts') that must be paid for.
For some reason your helpful comparisons never mention that both unicorn[1] and puma[2] ship with this basic functionality out of the box. One could almost think it is part of your sales strategy to have people notice this little 'limitation' only after they already deployed your product to production...
[1] http://www.justinappears.com/blog/2-no-downtime-deploys-with...
[2] http://blog.nicolai86.eu/posts/2013-02-06/phased-restarts-us...
I've been using Passenger since it was called Apache mod_rails http://www.concept47.com/austin_web_developer_blog/ruby-on-r... you have to remember that before the Phusion guys showed up, there was no easy way to run a rails server without proxying requests to mongrel, thin or something like that. instances could bloat in memory or die and your app could, for whatever reason, go down and you wouldn't know it. Did I mention that rails apps were also pretty slow back then?
They made deploying and maintaining rails an order of magnitude easier with Passenger, first with the mindblowingly simple installation process and later by introducing ideas like killing and spinning up new app instances after xxx requests, or spinning instances up or down depending on activity. All this with simple configuration switches out the box. Even the advances in Passenger 4 are pretty amazing (threaded mode, and out-of-band garbage collection, come to mind)
What I'm saying is, they've done a lot for the Rails ecosystem and while I'm not a fan of their new pricing strategy with Passenger or their marketing tack with Puma posts on this thread, I think its worthwhile to be a bit more gentle in chiding them because of their peerless contributions in the past ... plus their link is actually a very well written comparison
I don't see how their standing in 2008 excuses them to use shady trojan horse sales tactics to push their rather mediocre product in 2013.
Phusion Passenger is used to full satisfaction by many large parties, such as Motorola, UPS, Hitachi, etc. So if you can point out technical reasons why you think our product is "mediocre", please feel free to tell us, and we'll fix them.
The open source version of Phusion Passenger is not a crippled version. It is used in production by many large users, including New York Times, AirBnB, etc. Your statement that the open source version is "crippled" goes right against the fact that we've been actively developing the open source version ever since Enterprise came out. In fact, open source development has become more active after Enterprise than before, thanks to Enterprise funds. If you check our commits at Github you will see that the rate of development has accelerated. If you take a look at all the new features in the open source version of Phusion Passenger 4 you will see that it is improving at a tremendous rate.
It is not true that the open source Phusion Passenger drops requests and serves 502 errors to users on every single deploy. Upon touching restart.txt, the open source versions blocks requests and resumes them after having restarting 1 process. The blocking only happens for the first process, not for the ones after. At no point will requests be dropped or will errors be served. We even have integration tests in place to check for this. If you see request drops or errors in the open source version, please contact us and we'll have a better look at the problem. If it's a bug, we'll fix, it's that simple.
"popping up shareware nag-screens at random intervals" is completely false. There are absolutely no nag-screens in Phusion Passenger. The open source version of Phusion Passenger is open source, so if you don't believe me, then dig into the source code and tell me where exactly the nag screens are.
The lack of rolling restarts in the open source version is not a secret. Our documentation clearly mentions the differences between the open source and the Enterprise version. With a few clicks, you can find out what the open source version does and does not have.
And actually, the open source version does not "lack" rolling restarts, it just does not automate it for you. You can implement rolling restarts using Phusion Passenger Standalone (open source version!) in the same way you do with Thin and Mongrel, i.e. by swapping sockets. It works fine and some of our users do exactly this. It is just more work than the automated, polished, error-resistant version that Enterprise offers.
And finally, you Unicorn and Puma "fully-functional" while implying that Phusion Passenger is not. This is not true. There are features in the open source version of Phusion Passenger that Puma and Unicorn does not have. The reverse is also true. It is even true that Unicorn has some features that Puma has and vice versa.
From the dishonest spin that you put on everything you say.
I wrote:
That's equivalent to popping up
shareware nag-screens into my face.
You reply with: "popping up shareware nag-screens at random intervals"
is completely false.
There are absolutely no nag-screens
in Phusion Passenger.
These little 'misunderstandings' and strawmen add up.Consequently I won't even comment on your further spin-doctoring here.
I'll just encourage anyone interested in the matter to also read what EngineYard and UserVoice say about passenger;
https://blog.engineyard.com/2012/passenger-vs-unicorn
https://developer.uservoice.com/blog/2012/08/08/the-dark-pas...
Like I said before: errors during redeploy are not supposed to happen even in the open source version, and if they do happen then we are very interested in fixing them. Please tell us more. There is no need to spin this as being "dishonest". If you don't believe us, tell us about your problem, let us fix it, and verify for yourself that it is fixed. Only the facts matter.
As for the Engine Yard and Uservoice.com post:
1. All problems that the Engine Yard post talked about, were fixed 2 days after they published that article (http://blog.phusion.nl/2012/09/21/the-right-way-to-deal-with...). If you are still experiencing those problems, tell us, and we'll fix it. By the way, did you notice that EngineYard said something entirely different about Phusion Passenger and Unicorn later on? https://www.engineyard.com/articles/rails-server
2. Almost all problems that that the Uservoice.com talked about, have been fixed in Phusion Passenger 4.0, open source version.
3. There are also plenty of posts that describe migrating from Unicorn to Phusion Passenger, e.g. https://speakerdeck.com/arnvald/dot-dot-dot-but-we-had-to-ki....
So what does that mean? Experiences differ, for all sorts of reasons, some legit and some not (e.g. inefficient configuration). Neither kinds of posts automatically mean that Unicorn/Phusion Passenger is bad: there will always be people having problems with a particular technology. That's why we encourage people who have problems to contact our support forum.
Wait, what...
You edited this line into your reply hours after you initially posted it. Hoping I would miss it or something?
And in this very edit you have the nerve to suggest I edit my comment after the fact to spin shit around?
Look at the position of the 'popping up' phrase in my post. How would saying it in any way other than it's written make any sense, syntactically?
And why would I claim passenger pops up literal nag screens, when everyone knows that's complete nonsense?
I do appreciate you showing your true colors in this thread. I'll make sure to link to it every time I run into one of your 'PR excursions' in the future.
The cluster module is great, but it requires you to manage your processes yourself and to write your own load balancer. Phusion Passenger provides all this functionality for you for free, through a C++ core.
good writeup on the subject here: https://github.com/phusion/passenger/wiki/Puma-vs-Phusion-Pa...
content_type "text/event-stream" stream(:keep_open) { |out| settings.connections << out }
From Sinatra, which I assume is then deferring to EventMachine, courtesy of Thin. I'll see if there's a way of forcing EM directly in to the Stream setup...thanks for the pointer.
We recently wrote a demo demonstrating SSE on Phusion Passenger (https://github.com/phusion/passenger-ruby-server-side-events...). During writing of this demo, we found out that sinatra-contrib's streaming code relies on EventMachine. That means that sinatra-contrib's streaming only works on EventMachine-based servers, like Thin and on Goliath.
Based on my knowledge about Puma, I'm pretty sure SSE works fine on Puma as well. The Phusion Passenger SSE demo uses the Rack socket hijacking API (which we've blogged about: http://blog.phusion.nl/2013/01/23/the-new-rack-socket-hijack...) to implement SSE. This approach should work on Puma as well because it supports the Rack socket hijacking API too.
This makes sense because multi-threading is still a win under MRI even with the GIL, only so long as your app is io-bound (so threads can be switched out when waiting on io, for instance waiting on a db query).
Most web apps I've worked with tend to be io-bound.
https://github.com/jrochkind/fake_work_app/blob/master/READM...
https://github.com/jrochkind/fake_work_app/blob/master/READM...
Note: I'm an amateur and I know I'm not nearly optimized across many areas -- the app could be better, I'm not using JRuby (where multi-threaded shines, or so I read), so this is from a pretty novice perspective. But from here, Puma has been great.
Didn't get much attention when I tried to post it to HN when I did it a couple months ago:
https://github.com/jrochkind/fake_work_app/blob/master/READM...
This means that application servers can just keep stacking concurrent requests with perfect performance. If there was actually I/O being done that took 250ms, then you would find that it was the real bottleneck, and it would be the dominant factor in your benchmark, with the differences between app servers all but disappearing.
(I agree that with real I/O, there wouldn't be _exactly_ (eg) 50ms of waiting in every request; it would differ from request to request, and might slow down under heavier load. That's true, but I don't think it matters for what I was trying to test -- I was not trying to test how well a given rdbms can handle load, for instance; I was trying to standardize that, to test the app's performance. My simulation assumes an (eg) 50ms _average_ iowait time, by just assigning every request 50ms of wait. Or instead of 50ms, whatever average iowait you wanted to posit and test, and I tested a few. It is indeed a simulation, but I think it captures the significant things for what we wanted to measure).
However! I would very much welcome seeing the results from a test done by you (or anyone else), with an application that simulates (or actually does) I/O in a way that you believe is more realistic and leads to more instructive results. It certainly would be interesting to see if it led to different results than my tests, or not. I suspect it would not (because I think my app is realistically simulating the parts that matter, naturally! but I've been wrong before!)
Feel free to fork my code to do so, if my code is a useful starting point for you. Please do share your results!
Of course, you could also run tests with some actual real world app as well, instead of an app simulating a real world load in a standardized way like I used, and see what those results look like. I'd certainly welcome seeing that too! There's certainly plenty of different sorts of tests that could be done. I'd love it if people started doing some of them and sharing their results. I tried to contribute my best effort to that.
My apologies if I came out too strong.