3 ms·
No performance comparison with their working C code. Hrmph. Erlang's a better choice for this kind of thing because you don't have to worry about a lot of the
by davidw 18y ago
No performance comparison with their working C code. Hrmph. Erlang's a better choice for this kind of thing because you don't have to worry about a lot of the things that could go wrong in the C version, and it's a bit higher level than C, but still... C is fast and working code is working code.
- jlouis 18y agoI would presume the Erlang version is much smaller than the C version. Nobody argues that Erlang is faster than C, but it might be fast enough for the task at hand. Functional programs tend to be slower than imperative programs. They also tend to be much smaller. And they tend to be easier to understand and work with once the programmer gets the right mindset. This just shows another area where C is not the only competitor anymore.
- davidw 18y agoSure, all that's true, and are good reasons to reach for Erlang before C when writing something like this. It seems a bit weird to rewrite working code though, and it's unfortunate not to measure it. I would bet on Erlang not being that much slower than C, and like you say, much smaller, nicer, etc... so it would have been interesting to have some data to think about.
- erlanger 18y agoWhen dealing with high concurrency, Erlang will beat C.
- davidw 18y agoWhat is Erlang written in, again? Erlang makes it (a lot) easier to write high concurrency code, if that's how you define 'beat', but it's not "faster".
- erlanger 18y agoYes, you could theoretically struggle to write C code to work like Erlang, but processes are very cheap in Erlang, and distributed, parallel code is extremely easy to write. C performs well, but can be unstable; Yaws performs as well as Nginx. Erlang's greatest advantage is not in its vertical but its horizontal scalability, which does have consequences for performance.
- neilc 18y agoyou could theoretically struggle to write C code to work like Erlang Lots of people write non-blocking network servers in C (epoll, kqueue, etc -- libevent); that does not constitute "struggling to write C code that works like Erlang", but it still delivers a very high-performance end result. C performs well, but can be unstable C is perfectly "stable", it can just be hard to get right.
- davidw 18y agoWhere Erlang is really strong is that you can handle fairly long running processes that won't block other stuff that's happening. Of course you can find ways to do that in C, but it's just easier and way cleaner in Erlang. This works because of Erlang's internal scheduler.
- zacharypinter 18y agoCan't you just do something because it's interesting and fun? I'm pretty sure that was the biggest motivator here.
- imbriaco 18y agoThe original motivation was exactly because it was interesting and fun. When we got something working, I benchmarked it on my MacBook Pro and saw 1500 reqs/sec being handled on a single core. Those benchmarks made it much more real and so I decided to put the extra effort into making it ready for production. It may or may not be as fast as the FastCGI based C polling service that we had been using, but it's certainly more maintainable. I'd much rather manage three Erlang nodes than the 240 FastCGI processes that we were running. In fairness, we could have written a threaded poller in C and ended up with the same ease of management, but it would have been a heck of a lot more code.
- jimbokun 18y ago"In fairness, we could have written a threaded poller in C and ended up with the same ease of management, but it would have been a heck of a lot more code." What's the equivalent of Greenspunning when you find yourself trying to duplicate the features of Erlang in some other language? Do you just say "Greenspunning Erlang," or is it only proper to use Greenspunning when the other language is Common Lisp?
- aaronblohowiak 18y agoI don't think that writing a threaded poller in C would be trying to duplicate the features of Erlang. Epoll / kqueue (and historically, poll/select) are in c, made to be used with C. That being said, the 283 lines of 37S application code is impressive to me. It would be fun if they opened up this bit of infrastructure (or at least its functional spec) so we could add it to the programming language shootout. To save you the googling: "GreenSpunning is the ad hoc implementation of domain-independent language features in a language which lacks the feature; it can range from a simple one-line function or macro to the canonical description of GreenSpunning: a "half-assed implementation of half of CommonLisp''. " http://c2.com/cgi-bin/wiki?LevelsOfGreenspunning http://c2.com/cgi-bin/wiki?LevelsOfGreenspunning