N2O: Fastest Web Framework for Erlang over WebSockets

1,011 views
Skip to first unread message

Maxim Sokhatsky

unread,
Apr 28, 2013, 5:38:28 PM4/28/13
to nitro...@googlegroups.com
Greetings, Jesse and Community!

We at Synrc Research Center want to present a new fork from Nitrogen. 
We've been used Nitrogen in production and have some experience in it.
Our main aim is to investigate far further ways of Nitrogen evolution.
Project highlights:

-- Binary page construction
-- Binary data transfer
-- Pure WebSockets nature of events
-- Optimization for latency and capacity
-- Clean codebase

We called it Nitrogen 2 Optimized (N2O). Main feature is WebSockets
async interface for page updates. No processes spawn, works within
Cowboy processes. Page render is several times faster than
original Nitrogen.

We choose Nitrogen for simple and elegant way of typed HTML page
construction like in Scala Lift, OCaml Ocsigen and Haskell Happstack.
Templated based approach pushes to to deal with raw HTML, like
Yesod, ASP, PHP, JSP, Rails, Yaws, ChicagoBoss. N2O goes further
and optimize rendering from binary iolists instead of slow Erlang
lists originated by Nitrogen.

We’ve measured all existing modern web frameworks with latest
functional languages and Cowboy still the king. You can see raw
HTTP performance of functional and C-like languages with concurrent
primitives (Go, D and Rust) on VAIO Z notebook with i7640M processor:


We outperform full Nitrogen stack with only 2X downgrade of
raw HTTP Cowboy performance thus rise rendering performance
several times in compare to any other functional web framework
and for sure it is faster than raw HTTP node.js performance.

N2O doesn’t use JSON, all message data passed over WebSockets
encoded with native Erlang External Term Format which is easily
parsed in JavaScript with Bert.decode(msg) and helps to avoid
complexity on server-side.

Original Nitrogen was tested in production under high-load and
we decided to drop out nprocreg process registry along with
action_comet heavy process creation. N2O now creates only
one process for async websocket handler, all async operations
are handled withing Cowboy processes.

We feel free to brake original Nitrogen compatibility because
we want to have clean codebase and investigate future ways
of evolution. However we still able to easily port old Nitrogen
web sites to N2O.

We return back id and class semantics of HTML and removed html_id.
We simplify render without html_encode which should be handled by
application layer. nitrogen.js originaly created by Rusty for XHR
was removed due to pure WebSocket nature of N2O and native
jQuery handling. E.g. 

            #button { id=sendButton, text=<<"Send">>, postback=chat }

renders to:

<input id="sendButton" type="button" class="sendButton button" value="Send"/>
<script>$('#sendButton').bind('click',function anonymous(event) { 
      ws.send(Bert.encodebuf({source: Bert.binary('sendButton'), 
                              pickle: Bert.binary('R2LH0INQAAAAWXicy2DKYEt...'),
                              x: Bert.binary('undefined')}));});</script>

Despite early stages of project we decided to write this letter to
all users of Nitrogen. Our intention is to make all of them more
happy from using Nitrogen.

However we still continue to use original Nitrogen over XHR basically due
to customer's browser compatibility needs. Also we want to thank all
users who contributes code to the greatest Erlang Web Framework.

You can give stars, spawn forks and follow us here:

https://github.com/5HT/n2o-release -- Sample in form of Erlang release


-- 
Maxim Sokhatsky
Synrc Research Center


Jesse Gumm

unread,
Apr 28, 2013, 9:35:22 PM4/28/13
to nitrogenweb
Hi Maxim!

Very cool project.  I like the idea of pushing Nitrogen's limits, even if it means forking it and breaking backwards compatibility for experimental purposes. After all, that's the best way to try new concepts and experiments.

I actually noticed your Twitter post about it, and did a Google translate from Russian for your blog post (http://maxim.livejournal.com/407472.html), so I had an idea this was coming.

I definitely agree with many of the decisions you've pushed it: Binaries/iolists and websockets in particular.  The lack of websockets in stock Nitrogen is an obvious deficiency and one I've been planning on doing, but with backwards compatibility and a fallback to comet/ajax if necessary. Binaries as well, need more love, and a lot of the Nitrogen internals can benefit from being "binarized" to speed up rendering.

Overall, kudos to you guys and thank you for sharing!

-Jesse

P.S. I may want to steal some of your changes and merge them into mainline Nitrogen, if that's okay :)



--
You received this message because you are subscribed to the Google Groups "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nitrogenweb...@googlegroups.com.
To post to this group, send email to nitro...@googlegroups.com.
Visit this group at http://groups.google.com/group/nitrogenweb?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

Max Lapshin

unread,
Apr 28, 2013, 9:50:13 PM4/28/13
to nitrogenweb
As I've already mentioned in that livejournal's post, websockets are very cool, but they are not 100% ready for everywhere.

Don't forget, that nginx, packed in current distributions, still cannot proxy websockets. It means that in 99% cases one would not be able to put nitrogen on one IP with some other service.

So, websockets must have some fallback.

Jesse Gumm

unread,
Apr 28, 2013, 9:57:58 PM4/28/13
to nitrogenweb
Absolutely, I agree completely.

I wouldn't do a complete 100% switch toward websockets. If the browser and server support websockets, it would fallback, either to a flash-based socket solution (probably not) to emulate websockets (I did something like this years ago to build a trivia/chat system), or just fall back to comet (far more likely - no reason to muddle up the codebase with flash. Ugh, just saying that makes me feel a little dirty).

The positive thing is that at least nginx's current version does support websockets, but it'll almost certainly be a while (year or two?) before it's packaged into the standard distros (my Ubuntu 12.04 is using nginx 1.1, while the earliest nginx with websockets is 1.3).

But it never hurts to start preparing for the future.

-Jesse


--
You received this message because you are subscribed to the Google Groups "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nitrogenweb...@googlegroups.com.
To post to this group, send email to nitro...@googlegroups.com.
Visit this group at http://groups.google.com/group/nitrogenweb?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages