4 ms·
I find it a bit funny to see concurrency dragged out in a case that's pretty much a perfect example of where Ruby handles concurrency quite decently, both in te
by vidarh 12y ago
I find it a bit funny to see concurrency dragged out in a case that's pretty much a perfect example of where Ruby handles concurrency quite decently, both in term of performance, and compact, simple code.
E.g. his URL example:
require 'net/http'
require 'uri'
urls = ["http://www.cnn.com","http://espn.go.com/","http://grantland.com","http://www.newyorker.com/"]
urls.collect do |url|
Thread.new do
response = Net::HTTP.get_response(URI.parse(url))
puts "#{url}: #{response.code} #{response.message}"
end
end.each(&:join)
I'm not so convinced about the performance argument, though. I have a pure-Ruby statsd implementation collecting massive amount of metrics from dozens of servers and calculating averages, feeding time series to Redis, pulling them out and rolling them up back into Redis and to a Couchdb server for longer term storage - it was a "hack" I threw together to replace our (admittedly simplistic) usage of Graphite because Graphite does things to your disks that no hard drive should have to suffer through, and it's not breaking a sweat. I'm sure you can squeeze out a bit more with Go, but for a monitoring setup, if you're not spending most of your time waiting on IO in the kernel, I'm not quite sure what you're doing.
I can see their point on packaging and delivery, though, having had to deal with packaging up three sets of patched gems for three different Ruby versions just in our office environment + servers internally for an internal tool. One of the reasons I'm experimenting with my ahead-of-time/"mostly static" compiler for Ruby is that I'm very much for static binaries.
But we also already do have jruby which makes packaging a lot easier too. Granted I can understand people not wanting to deal with the JVM.
- th0br0 12y agoCould you elaborate on the negative hdd aspects of Graphite? I'm evaluating using it and would love to know more!
- vidarh 12y ago(the short-ish version: make sure you test it with a realistic number of metrics and updates coming in from a realistic number of servers; if it can keep up on hardware you're willing to throw at it, then by all means go for Graphite - it has tons of flexibility that makes it a convenient way to get started. Just expect it to need a fairly hefty amount of disk IO compared to the amount of data you feed it in; the interfaces to Graphite are simple enough and narrow enough you can replace it later if need be, once you know what parts of it you're using) Graphite essentially assumes that disk is cheap. Even fast disks. And either you're not collecting very big data sets, or you roll up to more rarely updated series very rapidly, or you have a hefty high performance RAID to put it on, or you distribute it over multiple servers. And for a lot of people it's probably true it'd be cheaper to just buy a suitable set of SSD's and doing RAID10 and/or spreading it out over multiple servers or something than spend time putting together something else. But if you start seeing yourself needing to scale up substantially, it may be worth thinking through exactly what your needs are and whether you can get away with less by giving up on some of what Graphite offers. And one outcome of the expectation of fast disk is simply that Whisper - the underlying storage code - makes some assumptions that leads to lots of unnecessary system calls; lots of seeks that turns out to be no-ops, and small reads and writes. All of them are common problems that people tend to be unaware of, but they were painfully obvious after some strace usage. Just fixing that would improve Graphite performance substantially even without ditching functionality, but I really did not feel like digging into unfamiliar Python code to get halfway there when I could just as quickly replace the whole thing. That assumption of being prepared to use a fast RAID just for some metrics for our dashboards and monitoring didn't sit well with me in general. And given that we basically just used it to aggregate a set of time series over relatively recent history and don't need most of Graphite's features, and that we don't particularly care if the occasional server crash takes out some of the most recent history with it on one server when we can cheaply run a second collecting most of the same data (and would've ended up with more than that with Graphite), it seemed like worth doing things differently. I basically replaced Graphite (the subset that we use of it) with this, in the course of a few days: * A tiny statsd implementation in Ruby, that flushes data to a Redis with disk snapshots turned off. It does this every 10 seconds. * An aggregation script that's a couple of hundred lines that uses key based filtering to aggregate all 10-second data for any five minute interval into a new time series, and again aggregate all five-minute interval data into hourly time series, and so on, and that moves all data older than a few hours to a disk backed CouchDB (could put it into "anything" really) * A tiny Sinatra app that provides a somewhat Graphite compatible JSON output (but with no attempt to support the Graphite query syntax or server side image rendering. * A slightly modified Graphene version to build our dashboard on. It does by no means do everything Graphite does, but what it does, it does without brutally hammering disk. It consume a tiny fraction of the resources Graphite used too.
- ksec 12y agoi am more interested in your AOT static Ruby Compiler, anything to share on that front?
- vidarh 12y agohttp://www.hokstad.com/compiler http://www.hokstad.com/compiler Note that it is very unfinished, and I'm moving very slowly with it. I'm overdue for posting another blog post or two about it - I have two that just needs editing, and a third halfway done. At current pace I'm realistically hoping to be close to having it self hosted by christmas. (the big caveat of course being that getting it self-hosted is not the great indication of feature completeness it may sound like, since you get to cop out by not using constructs you don't feel like implementing yet) To be honest, it kind of veered off course from me just illustrating some low level techniques to quickly bootstrap a very primitive language, to me deciding I wanted to experiment with a Ruby compiler, and so the writing is all over the place. One of the things that motivates me apart from writing about it, is to try to figure out how dynamic Ruby really need to be, and how much static information you can "recover". On the surface, Ruby is notoriously tricky, because e.g. you can't tell based on local information even what piece of code will be called. E.g: t1 = Thread.new do loop do puts 4 + 5 sleep (1) end end sleep(rand(3)) class Fixnum def + other 42 end end t1.join It's no fun reasoning about that "puts 4+5" when even integer addition may suddenly stop working after a random interval... But of course in real life, most of the really hairy nastiness doesn't occur outside of scary examples (I've never seen anyone override stuff in Fixnum to do anything useful, for example), and could easily be documented as unsupported in an AOT compiler, allowing both making the code substantially more static, inferring types in quite large sections of programs eventually, and making it faster (as a side note, there's a Truffle based backend on the way for jRuby that achieves much of this by basically assuming the normal case in lot of situations, but "de-optimizing" when assumptions turn out to be wrong, which will get many of the benefits). I'm hoping to essentially find space where the compiler can basically declare "mostly safe" default behaviour, such as assuming nobody overrides Fixnum#+, and optimize for that, with switches or pragma's to re-enable "standard" behaviour for those cases where someone is in fact doing something really silly and expecting it to work.