
Erlang/OTP architectures: Cowboy - kansi
https://medium.com/@kansi/erlang-otp-architectures-cowboy-7e5e011a7c4f
======
technion
I load tested (using wrk) nginx serving a two line, static HTML file, against
a basic Cowboy service that parsed parameters, did an ETS lookup, and rendered
several hundred json elements, on my EC2 micro.

nginx came in at 14612 requests per second, and the dynamic code under Cowboy
option came in at 13336 per second.

The same server was pulling 147 requests per second for a "hello world" rails
application (Unicorn, production mode). Cowboy really isn't joking when they
talk about performance.

~~~
gozo
I guess you can either see it as how much faster Cowboy is or how much more
useful Rails is. It's nice if you have a lot of Erlang code already, but if
you're making a web application from scratch, performance is pretty far down
the list and I would stick to the half dozen stacks that are proven. Erlang
can make sense sometimes, but it's probably not(!) comparable to Rails in
those cases.

Edit: Eh, I forgot a "not" in the last sentence, which is now added.

~~~
digitalzombie
Cowboy could serve API/data stuff instead.

RoR is productive for website/web apps.

I mean looking at just request per sec that metric would be much better for
something like API/data serving app.

~~~
simoncion
> Cowboy could serve API/data stuff instead.

> RoR is productive for website/web apps.

Phoenix [0] uses Cowboy as its HTTP server.

[0] [http://www.phoenixframework.org/](http://www.phoenixframework.org/)

------
rdtsc
Cowboy is great. It is a very perfomant, well designed and implemented piece
of software. Also is mostly the work of one person -- Loïc Hoguin and his one-
man 99s (Nine Nines) company.

[http://ninenines.eu/](http://ninenines.eu/)

So if you read this Loïc, thank you for all your work and for sharing it with
the community.

------
rekoros
Great to see Cowboy and Erlang in general finally getting noticed! (Mostly via
Elixir, it seems, which is kind of ironic.)

Our company has been sponsoring Cowboy development for about 18 months
([https://medium.com/@abs/what-we-learned-from-sponsoring-
an-o...](https://medium.com/@abs/what-we-learned-from-sponsoring-an-open-
source-developer-for-a-year-4438568a1cfd))

Join us, if you can.

------
nailer
Also relevant to Elixir folk using Phoenix, which uses Cowboy code.

------
striking
Y'know, I tried using Erlang/OTP with rebar3 and cowboy to make a web app. And
it turns out that I couldn't even figure out where to put my code, much less
how to run it.

It seems a lot of people are having success with Erlang but I can't figure out
how these applications actually run; it almost seems like there isn't a single
step-by-step tutorial on the Internet for setting up an Erlang system using
"best practices."

Am I just missing something? Because I feel like I'm hugely missing out.

~~~
plainOldText
Here's the cowboy user guide:
[http://ninenines.eu/docs/en/cowboy/1.0/guide/](http://ninenines.eu/docs/en/cowboy/1.0/guide/)

You can also clone the repo and checkout the examples:

Make sure you have erlang installed

    
    
        $ cd examples/hello_world
        $ make
    
        $ ./_rel/hello_world_example/bin/hello_world_example start
        OR
        $ ./_rel/hello_world_example/bin/hello_world_example console
    

then visit localhost:8080

~~~
simoncion
This gets a Cowboy application up and running, but it doesn't tell you what to
do to write your own Cowboy application, and doesn't give you a very firm
understanding of either how the hello_world example works, or how to modify it
to suit your needs.

As someone who's been down this road in the past, unless you're already
_rather_ familiar with Erlang and OTP's conventions, the gap between the
User's Guide and the API documentation is _far_ too large to make connecting
information you learn from one with information you learn from the other easy.

I've summarized my personal struggle with the Cowboy user's guide and
documentation in my other comment in the thread. Please read that comment
before you downvote this one. :)

~~~
plainOldText
As far as I know there's no such thing as a `Cowboy application`. They're all
Erlang/OTP applications. Sure, there's a learning curve associated with OTP
apps, but since Erlang is a bit of an exotic language, I think it's
understandable.

If you'd like to learn about the concepts behind an OTP application, you can
read this guide: [http://learnyousomeerlang.com/building-otp-
applications](http://learnyousomeerlang.com/building-otp-applications) or the
Erlang documentation for OTP apps (which is pretty good I think).

Another viable option in my opinion would be to just look into the Phoenix
framework for the Elixir language. Under the hood it uses cowboy. And it feels
a lot like Rails.

~~~
simoncion
I guess you didn't read my other comment in this thread. Please read it. ;)

> As far as I know there's no such thing as a `Cowboy application`.

From one pedant to another: "I _know_ that." >:)

However, there _is_ (to put it _loosely_ in OTP terms) a set of Cowboy
behaviours. Your application is _expected_ to implement one or more of these.
While the API for these behaviours is reasonably documented, the Cowboy
equivalent of the -say- gen_server "User's Guide" is so sparse as to be almost
non-existent.

~~~
plainOldText
Okay. Read it now! :-)

I think one reasonable strategy of learning how some piece of software works
or is meant to be used – especially when documentation is poor – is to just
look at the source code (tests included).

I'm just getting started with the Phoenix framework, and I'm learning Elixir
at the same time and reading through the source code helps me a lot, because:

    
    
        1. I can check out how things are implemented
        2. I get to read some idiomatic Elixir which helps me learn the language better
    

One can get reasonable understanding of software at the interplay between
reading the docs and reading the source code.

~~~
simoncion
I generally agree that -in the absence of sufficient documentation- reading
the tests and source for the project is generally the best way to learn how to
use a project.

However. If the language the project is written in is wildly unfamiliar to
you, and you've never had experience with a similar language, then this
technique is often... less than satisfying.

From your comments, it appears that you have more than a passing familiarity
with Erlang/OTP. You _have_ to admit that it would be _substantially_ harder
to understand both Elixir and Phoenix without your understanding of Erlang. :)

------
izend
I'm writing a game server using Cowboy and websockets, it was extremely easy
to setup and so far the performance has been very fast.

~~~
sntran
Glad to see another person attempting it. There are a few (including a
commercial product, a Kickstarter project, and me) but most have been
abandoned, AFAIK.

------
wws
ChicagoBoss is like a Rails for Erlang. Uses Cowboy as httpd. I've only played
with it a little, so I can't say how well it holds up in production, but it
sure seems neat.

[http://chicagoboss.org/](http://chicagoboss.org/)

