5 ms·
I think Ruby on Rails should be more asynchronous. Doing a http request or a sql query blocks everything until it finishes. The solution is to spawn many instan
by speedgoose 6y ago
I think Ruby on Rails should be more asynchronous. Doing a http request or a sql query blocks everything until it finishes. The solution is to spawn many instances, but it uses a lot of memory and a slow http service may block all rails instances very quickly.
- dfischer 6y agoElixir is the solution to this with similar ergonomics.
- syspec 6y agoI've been experimenting with it, and it definitely has the feeling of working in rails / ruby. My only gripe is that the tooling is not as mature as rails. I use rubymine and the debugger has truly spoiled me. I tried to get the debugger going with a third party plugin for Intelli-j but it would crash when inspecting variables. Any tips?
- ollysb 6y agoI think most elixir dev's have a CLI based workflow where IEx.pry works very well.
- dfischer 6y agoThere is not much I can comment on editor support as I’ve had the experience of both successfully and unsuccessfully using various debuggers in editors. If you jump into IEX and use the built in introspection it’s some of the most advanced tooling I’ve ever seen in any language. Especially when doing OTP-level topology.
- user34234 6y agoThe company I work for (mostly standard Web Dev) uses almost exclusively Elixir for any backend work. Only the fanboys of Elixir and functional everything are happy with it, just to be different to everyone else. The experience is terrible: Tooling (editor plugins, tests runners, IDEs (oh, there are no IDEs...), debugging) is like going back 20 years. There are no libraries for the most basic stuff you get almost by default on the Ruby, Python, Node or Java ecosystems. So we end up reinventing half assed solutions to anything we need to do. Some days I think we would be sooo much better by just using Rails or Django. Of course, concurrency and the Erlang VM are awesome and the perfect fit for the web... if your problem is performance, it will solve that problem for you of course... other than that, is all wasted time in my opinion from my experience after years of using it.
- cpursley 6y agoReally? I've been able to find everything I need in the Elixir ecosystem from auth to background jobs and one of if not the best GraphQL server implementations out there. Do you mind sharing which libraries you found missing or incomplete?
- user34234 6y agoYes, in fact we have ourselves published a few open source packages out of the need we had to build them. The latest incarnation of this problem, was when we had to validate RUT codes (a tax code with a checksum we use here in Chile). Options for Python [1], options for Node [2], options for elixir [3] (don't mind to click, it's a list with nothing to do with RUTs or modulo11 validations). So we had to implement it ourselves. Looking for information we found example implementations [4], where as you can see you have example implementations even for Asterisk Dialplans (!!) but no mention of Elixir. [1] https://pypi.org/search/?q=rut https://pypi.org/search/?q=rut [2] https://www.npmjs.com/search?q=rut https://www.npmjs.com/search?q=rut [3] https://hex.pm/packages?search=rut&sort=recent_downloads https://hex.pm/packages?search=rut&sort=recent_downloads [4] https://es.wikipedia.org/wiki/Anexo:Implementaciones_para_algoritmo_de_rut https://es.wikipedia.org/wiki/Anexo:Implementaciones_para_al... There are many more examples. Of course you get libraries for the "standard" stuff, it is when you get into the detailes, and that happens when you are already too deep into your project, that you realise all the missing pieces. Also, what code editor do you use? we've tried everything, and seems the best option is you grow a beard and go emacs/vim. The VSCode plugins hog your laptop and are really inconsistent, incomplete and sluggish [1] [2]. [1] https://github.com/JakeBecker/elixir-ls/issues/54 https://github.com/JakeBecker/elixir-ls/issues/54 [2] https://github.com/elixir-lsp/elixir-ls/issues/96 https://github.com/elixir-lsp/elixir-ls/issues/96 Of course there is no IDE similar to intellij, rubymine or pycharm.
- cpursley 6y agoFair enough, thank you for sharing. I've had good luck with VSCode but I've never really been an IDE user (even with Ruby) so I can't comment much on that.
- syspec 6y agoI thought all DB access was pooled in rails, and the server most everyone uses (Puma) multi threaded? How would a SQL query block other threads? Sincere question
- cpursley 6y agoYes, it's called Elixir with Phoenix :)
- welearnednothng 6y agoThis is not correct. When Ruby is doing I/O such as this is the only time it’s not blocking. This is due to Ruby, not specific to Rails. Here are a few references: https://github.com/puma/puma/issues/1003 https://github.com/puma/puma/issues/1003 https://thoughtbot.com/blog/untangling-ruby-threads https://thoughtbot.com/blog/untangling-ruby-threads
- speedgoose 6y agoI have to admit that I have not used puma for development. Edit: your links show that indeed its blocking and you need to spawn many threads/instances, which use memory.
- MXfive 6y agoExtra processes (workers) consume extra memory, threads do not.
- welearnednothng 6y agoSo, threads and instances are two very different things. They both use memory, though threads use far, far less memory - just like in other languages where you would use threads for concurrency. When Ruby's GIL is waiting on I/O, it allows other threads to do their work. Per the first link, from the author of Puma: "The reason for that is waiting on IO (talking to a DB, etc) will allow another thread to run" The threads don't run in parallel, but they do run concurrently. While this isn't the panacea of performance, it does work well with many web apps which tend to be I/O bound (waiting for a database or remote service). So to your original of "Doing a http request or a sql query blocks everything until it finishes. The solution is to spawn many instances" - an HTTP request or SQL query will, in fact, allow other threads to execute while waiting for a response meaning you can rely on threads, rather than instances, and maintain a very low memory footprint. If you like Ruby but want true multi-threading and parallelism, I'd highly recommend taking a look at JRuby (https://www.jruby.org https://www.jruby.org). Those guys have done an incredible job with it.
- joelbluminator 6y agoI don't think that's true - the Ruby VM switches threads when blocked on IO like http or db. This happens regardless of what Rails is doing. Maybe you're talking about suboptimal usage of cores...afaik it's indeed being worked on in the Ruby community and it's not something Rails can solve.