Using Go to improve your Ruby application's performance
antoine.finkelstein.fr
antoine.finkelstein.fr
If you were going to consider this seriously, then you should have the target app start once, listen for comands on some channel like a socket, and have it return information. JSON is probably a little too verbose for this kind of use-case as well, but it depends how efficient Ruby would be at unpacking alternative serialization formats.
There has been talk of incorporating this ability and slim executables go (I think it might even be in the roadmap now).
It's not a terrible one, though. You don't choose Ruby for its performance. If you find yourself creating and returning lots of JSON with this, that should be a clue that you should be pushing more functionality down to that lower level, and just returning the bulk results back up.
> Ruby uses green threads (meaning only one CPU will get
> used) and they are no easy equivalent to Go channels.
Restriction to a single core is a consequence of the GIL. Also Ruby uses native threads, not green threads, since 1.9.The author's `execute` method is dangerous because it doesn't escape its arguments.
[1]: Perl has plenty of event loop choices, but in terms of trying to maintain thousands of live SSL connections at scale it's a terrible, terrible choice for that connection manager. But it was just fine as a service provider.
A Ruby extension written in Rust is also one of the first production uses: skylight.io
But it says Go, because the author used Go, but apparently some people are tired of hearing about Go.
(It's basically a golang port of Resque::Worker)
This article could have been written in 1998, titled "Using C to improve your Perl application's performance".
I'll say this about this strategy. For most web apps (and ruby is mostly used in webapps), it's usually more robust to just write a go background worker listening over RabbitMQ or the like and just shove messages around as a service.
JSON.parse(`go run json.go`)
No. `exec #{Rails.root}/tmp/go_#{m} #{arguments}`
The escaping leaves a bit to be desired.Otherwise you leave yourself open to future security issues, especially if you keep API keys or DB passwords in ENV.
JSON.parse(`./json`)Even without connecting directly (which is just as trivial as reading a response from exec), you should be looking at a formal message passing system. This also allows you to easily distribute these dissonant applications, which is a good idea when you're talking about "utilizing all the CPUs available" and potentially high network usage.
http://www.confreaks.com/videos/5076-RubyConf2014-harnessing...
And my PyConZA talk slides:
https://speakerdeck.com/pyconza/pyconza-2014-inspired-by-lis...
For example, this doesn't look appealing to me because it adds complexity and makes your codebase harder to work with.
It's a neat hack, but I think in reality there would be very few cases where this would be a good idea.
Please, for the love of all that is holy, read up on `Shellwords.escape`. NOW.
Or at least do the rest of us a solid and post where you're setting up these gigantic security holes-waiting-to-happen in production, so we know where NOT to put personal data...
Personally I always favor solutions that don't require changing language.
As for RubyMotion, I thought it already supported any UNIX system.
And no, RubyMotion does not act as a general purpose Ruby, it only targets iOS, OS X, and Android.
http://blog.skylight.io/bending-the-curve-writing-safe-fast-...