[erlang-questions] Cowboy (Erlang) VS Haskell (Warp)

Loïc Hoguin <>
Tue Jun 25 21:21:11 CEST 2013

On 06/25/2013 08:54 PM, BM Kim wrote:
> On 06/25/2013 08:38 PM, Loïc Hoguin wrote:
> [...]
>>>>> blob() ->
>>>>>       [<<0:8>> || _ <- lists:seq(1,4096)].
>>>> First, try to replace blob/0 function with this:
>>>>     blob() -> <<0:(4096*8)>>.
>>>> Then, restart the test and report ;)
>>> Hi,
>>> Thank you very much for pointing out the obvious mistake...
>>> After correcting it, I got improvement from 5940 req/s to 8650 req/s...
>>> But still much slower than the haskell warp-server, which has throughput
>>> of 38000 req/s...
>> That's not surprising at all, you are performing the same thing exactly all the time, so of course Haskell is going to be fast at this. Same goes
>> for JIT enabled environments like Java. The JIT can easily compile it to machine code once and be done with it.
>> You're not actually testing the HTTP server, or even the language performance, you are testing the ability of the platform to optimize one operation
>> to death.
>>> But I have another question regarding blob/0. Is it going to be evaluated
>>> only once (like GHC would do) since it is a pure expression? I'm not
>>> so sure, since erlang is not pure and any function can have side-effects
>>> which you can't mark as with the IO monad in Haskell...
>> Erlang doesn't do that. Closest is at compile time when A = 1 + 1 becomes A = 2 in the compiled file, but it's only done for a very small subset of
>> all expressions.
>> Erlang shines not in synthetic benchmarks, but in production, when thousands of clients connect to your server and expect their requests to arrive
>> as quick as if they were alone on the server. Erlang is optimized for latency, and this latency will be the same regardless of there being only one
>> user or ten thousands.
>> Your benchmark on the other hand is evaluating throughput. Throughput is boring, and not really useful for Web applications. (See Max' email for
>> more details on that.)
> Thank you so much, for your helpful and insightful explanation, which gives me a new
> perspective on my current benchmark-strategy and expectations...
> If it is not too much trouble, can you me some further advice regarding erlang
> performance in general and using the cowboy library "efficiently", if there are some
> issues/tricks which are not documented in the manual but I should be aware of?

The tricks are documented in either the Cowboy manual or the Ranch 
manual (for things relating to sockets). But there aren't many of them 
and you shouldn't start with these questions. Ask yourself whether the 
project enables you to do what you need instead.

There's no doubt that Erlang fits your needs if it's a Web project. The 
only gotcha would be that you want to use a NIF for image manipulation 
(there isn't any pure Erlang lib anyway at this time), and you want to 
use the OpenCL NIFs for any heavy computation. You can also use Erlang 
to handle clusters of Python instances or any other platforms, like has 
been done by many people (see CloudI for example, if you have that kind 
of need).

> by the way: can you recommend some opensource erlang projects incorporating the
> cowboy library that I can learn from?

I'd look at n2o, axiom, ChicagoBoss, or other frameworks, in that order.

Loïc Hoguin
Erlang Cowboy
Nine Nines

More information about the erlang-questions mailing list