7 ms·
Ruby on Rails 4.0.0.beta1 released
- jotto 14y agodoes threadsafe and ruby 2.0 mean we can create multiple instances with something like unicorn without forking the entire codebase?
- andrewvc 14y agoFunny thing about unicorn is, forking is core to its design. It may handle threading now, but when I last looked at its code fork() and traditional IPC via signals were core to its operation. Puma looks like the more thread-oriented choice these days.
- nachteilig 14y agoLast I looked Puma and jruby were the go-to options for threaded stuff.
- FooBarWidget 14y agoUnicorn does not handle threading now. :) It never had, and according to its author never will. Phusion Passenger Enterprise 4 is also thread-oriented.
- atambo 14y agoRuby 2.0 still has the GIL so if you want to run a threaded web server you'll still need to be using rubinius or jruby.
- jrochkind1 14y agoONLY if it's important to you that one process be able to run multiple threads on multiple CPU cores concurrently. Even without this, there are MANY use cases where multi-threaded concurrent request dispatch makes a LOT of sense. For instance, the recent controversy about heroku routing, right? With MRI or another interpreter with the GIL, you'd want to run one app process per CPU core -- but having each of those processes also do multi-threaded request handling can still even out latency (that is, avoid those awful ~95th+ percentile latencies in the heroku routing debacle), and increase overall throughput. Especially if your app, like most but not all web apps, is more I/O bound than CPU bound (waiting on DB, disk, or external APIs).
- nefasti 14y agoAny reason ruby still has the GIL and not moved to a thread implementation?
- steveklabnik 14y agoMatz likes the fact that it Just Works and you can't accidentally have weirdness based on how your code runs. There aren't any plans to remove it at this time.
- 33degrees 14y agoI can imagine a whole bunch of gems suddenly breaking if this changes...
- steveklabnik 14y agoThat's true, but I don't buy that argument: look at how fast everyone has updated their gems to be Ruby 2.0 compatible. The Ruby world likes running on the edge; if MRI forced us to consider thread safety, we'd learn about the issue much quicker as a community. Since we'd be forced to. ;)
- 33degrees 14y agoOh I don't doubt that the community would move quite quickly to support it, but it certainly wouldn't be without some bumps along the way!
- FooBarWidget 14y agoThe GIL makes a lot of things in the Ruby interpreter much easier to implement.
- jrochkind1 14y agoI'm not sure what you mean by 'forking the entire codebase'. Even if Rails3, though, Rails supported multi-threaded request dispatching IF you had an app server stack that supported it. In Rails3, you just had to explicitly turn it on with `config.threadsafe!`. Rails4 makes that the default, always on. That's really the only difference. There are at least a few concurrency-related bugs that have been fixed in Rails4 (I'm actually not sure how many), but even Rails3 was officially documented to do multi-threaded concurrent request dispatch just fine. (Actually even Rails 2.2 was!) Finding a mature, reliable, well-documented app server stack that supports multi-threaded concurrent request dispatch may be harder. I can not say which do and which don't, but there are at least some potential options (including puma, which, if I understand it right, has multi-threaded concurrent request handling as part of it's original core use case). I AM hoping that Rails4's "multi-threaded request dispatch on by default" situation will make the community pay more attention to this use case, result in more app servers supporting it first-class robustly, and any remaining bugs around concurrency being found and fixed. While Rails3 was documented to support this anyway (since Rails 2.2!), it has been mostly ignored by the community, for some reason. (Sadly, while Passenger Enterprise 4 will support multi-threaded concurrent request dispatch, the Passenger folks are intentionally reserving this feature for Enterprise, the free one won't)
- jeltz 14y agoRuby 2.0 means less memory usage with unicorn since the GC in Ruby 2.0 is copy on write friendly.
- FooBarWidget 14y agoMemory savings would be similar to when you used Phusion Passenger or Unicorn in combination with Ruby Enterprise Edition, which also has a copy-on-write friendly GC.
- FooBarWidget 14y agoYou can already run multiple instances of Unicorn. In fact, Unicorn is designed to be a multi-process app server. When running multiple (single-threaded) processes you don't need to be thread-safe. This is the process model that Mongrel and (open source) Phusion Passenger use as well. But what you probably meant with "multiple instances" is "multiple threads". You can't do multiple threads with Unicorn, it's explicitly designed not to handle multithreading. Instead you should use an app server that's capable of multithreading, e.g. Phusion Passenger Enterprise 4 which is hybrid multi-process/multithreaded. The Phusion Passenger Enterprise 4 multithreaded stack is already being tested or used in production by multiple organizations. We've been using it in production for months without problems. Also, multithreading does not require Ruby 2.0. Ruby 1.9 works just fine.
- steveklabnik 14y agoHello everyone! I am MEGA EXCITED for this release, as it's the first version in which I'm a committer. Wooo! In addition, 954 other intrepid Rubyists in total contributed to this release: http://contributors.rubyonrails.org/edge/contributors http://contributors.rubyonrails.org/edge/contributors Please note that this is a beta, not an rc, so some things may be a bit wonky. Please file an issue on GitHub and I will do everything I can to help you help us iron out all the kinks. ❤❤❤ (Also, I am on a plane and my battery is almost dead, so I may drop out of this thread soon. Ill read it when I'm home.)
- grey-area 14y agoI'm curious to know if these examples of potential SQL injection tested against 3.2.11 have been dealt with in 4.0? Would be great to see these possible problems tidied up. http://rails-sqli.org/ http://rails-sqli.org/
- steveklabnik 14y agoI am not a member of the security team, but it's my understanding that all security patches were also applied against master where appropriate. (The security team is a subset of the core team, in accordance with least privilege and all that.)
- grey-area 14y agoOK. I've checked against 3.2.12, and at least one isn't fixed, so it might be worth passing the link on to the security team. They'll all be easy fixes, and it'd be great to see them fixed (if not already) in 4.0. Thanks for contributing Rails 4.0 - I'm excited to try it out, in particular the new caching looks great.
- stiff 14y agoThe examples here do not include SQL injection from known CVEs and are not vulnerabilites themselves, only potential misuses of the methods. What would you like to have changed here? The methods work fine as long as you do not explicitly embed a user-supplied string in a larger SQL fragment.
- newhouseb 14y agoI'm not a rubyist but I'm really excited for the russian-doll caching and really hope it catches on in other frameworks. Data dependency tracking makes everything from straight-up caching to real-time updates effortless and I think is one of the few places where an ORM can be really helpful (queue the two hard problems quote about cache-invalidation and naming things). Quora has been doing this since the beginning and I'm surprised it hasn't caught on in other open source (namely python) frameworks to the same degree, hopefully RoR will add some fuel to the fire.
- clivestaples 14y agoIf I remember correctly, Adrian Holovaty said something about exploring pjax solutions for Django when he returned to help manage the project. It would be neat to hear more about his ideas if I missed them posted somewhere...
- riffraff 14y ago> (queue the two hard problems quote about cache-invalidation and naming things) I think you meant "cue", otherwise please help a foreigner with this english expression's meaning.. queue onto what?
- newhouseb 14y agoYep, you're correct. "Queue" is just the programmer in me typing.
- 5vforest 14y agoWhat is the "Rails way" of doing AJAX calls and updating the DOM? I've been embedding Backbone views in the parts of my app that are the most interactive, but I feel like there's gotta be a better way.
- awj 14y agoAccording to recent discussions, turbolinks. It's built into Rails 4 and essentially works by making a call out to the server to fetch raw html and replacing some/all of the DOM with the result. Personally I just use Backbone and try to structure things in whatever way seems natural. It looks like there's been a lot of work done in integrating Ember.js if you want to look into that.
- JuDue 14y agoTurbo links is more suited to traditional web pages. Backbone for single page mini-apps.
- ibrahima 14y agoFor traditional web pages does it ever make sense to use Backbone/Ember/etc? I've used Backbone on one project and I kind of like the MVC aspect for some things but the thing I'm working on right now is more of a traditional web app. There are some interactive forms where it kind of makes sense to have a model and a view that reacts to changes in the model, but in the end the form is POSTing to a standard rails controller rather than using AJAX calls to update fields when they change. Right now I'm handling that manually since there aren't too many fields but I wonder if using something like Backbone would be a good idea for this use case.
- steveklabnik 14y agoIn the recent discussions about Discourse, it was said that on slower connections, it feels way snappier than a server-side solution would be. Frankly, I'm a server-side guy, so I prefer that kind of development, but there are advantages to SPAs, and like any good engineer, you should use the right tool for the job. Rails is modular enough that you can do whatever you want, Turbolinks is just a gem, so if you don't want to use it, you can just pull it out of the Gemfile. If be willing to bet that the less dynamic interaction per page, the less an SPA makes sense. ;) That said, I can also see how something like Ember gives you a nice way to do API-first development, so even if your site is more static, it could make sense. As always: It Depends. Don't believe anyone who tells you they have a silver bullet.
- JuDue 14y agoSorry for the naive question... But does this help Heroku's woes?
- xutopia 14y agoNope. The issue at Heroku is before the request has a chance to talk to the rails application. That is why so many people were annoyed that the reporting tool that analyzes speed of the rails application did not report the time lost.
- mrmagooey 14y agoIs there a Turbolinks equivalent for Django? Or something platform agnostic (I couldn't tell if that was the case with Turbolinks)?
- steveklabnik 14y agoTurbolinks is 100% Coffeescript; you could easily add it to a Django application by copying the assets out of the gem: https://github.com/rails/turbolinks/blob/master/lib/assets/javascripts/turbolinks.js.coffee https://github.com/rails/turbolinks/blob/master/lib/assets/j...
- tnorthcutt 14y agoSince Turbolinks is a Ruby gem, it's not exactly platform agnostic :). Hopefully someone else has an answer for Django, but you might take a look at https://github.com/jacobian/django-pjax https://github.com/jacobian/django-pjax and http://www.youtube.com/watch?v=3ml88L39cng http://www.youtube.com/watch?v=3ml88L39cng Edit: aaand steveklabnik knows more about this than me; listen to him.
- egonschiele 14y agoHow is live streaming implemented?
- steveklabnik 14y agohttps://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/live.rb https://github.com/rails/rails/blob/master/actionpack/lib/ac...
- adml 14y agoI am writing an upgrade handbook that covers the important deprecations and new features in detail: http://www.upgradingtorails4.com/ http://www.upgradingtorails4.com/
- ghiculescu 14y agoWhat's the recommended alternative to ActiveRecord Observers? I know they aren't perfect, but I wasn't a fan of cluttering my models with lots of after_commit - is there a better way?
- timdorr 14y agoThey are still maintained, they've just moved to a separate repo/plugin: https://github.com/rails/rails-observers https://github.com/rails/rails-observers
- spohlenz 14y agoOne option would be to use a service object (e.g. UserCreator) which would encapsulate the action (saving a user) along with the action to be taken (delivering a signup email). With external observers, it's not always obvious whether they are enabled or not. Service objects make this more explicit and are easier to test as well.
- byroot 14y agoI don't know if it's recommended but for simple cases where I just want to trigger some methods on multiple models I just use a concern: https://gist.github.com/byroot/5036110 https://gist.github.com/byroot/5036110
- hayksaakian 14y agoHow well does rails 4 play with mongoid? Any breaking changes I should be aware of?
- stiller 14y agoThis question would be better addressed to the Mongoid team, but it looks like they're working on it. I would expect an announcement when they consider it stable enough for production.
- steveklabnik 14y agoI'm not sure, because I don't use it, but edge mongoid at least claims to be compatible: https://github.com/mongoid/mongoid/blob/master/mongoid.gemspec#L22 https://github.com/mongoid/mongoid/blob/master/mongoid.gemsp...
- davidw 14y agoIs the web socket story substantially the same? In other words, Rails just isn't that great a platform for it? I think Rails is great, but this is one area where it's not a good choice.
- steveklabnik 14y agoWe don't do anything specific with WebSockets. ActionController::Live may be able to help you there, in theory, but I'm not incredibly educated on the subject, to be honest.
- VeejayRampay 14y agoThe general opinion in the Rails ecosystem seems to be that WebSockets don't solve any real problems and that they are a toy. The only mentions of WebSockets I've seen from people invested in Rails are mostly made of people actually deriding them and passive-aggressively making fun of people that use them or want to (generally in a bunch with MongoDB, Hadoop, Cassandra or other modern big data tools that don't fall naturally in the Rails ecosystem). But then again, it's not like they have an infinite amount of time to invest into everything and anything and they worked on SSE for Rails 4 on top of shitloads of additional goodies, patched a lot of security issues so overall I'm pretty happy as an end-user.
- DanielKehoe 14y agoHere's an article that shows how to set up both Rails 3.2 and 4.0 with Ruby 2.0. Uses some new features of rvm. "With both versions on your machine, you’ll explore the new features of Rails 4.0 while continuing to develop projects with the most recent stable version." http://railsapps.github.com/installing-rails.html http://railsapps.github.com/installing-rails.html