Páginas

2012/03/07

I'm presenting: Node.Net a real alternative to Node.JS (Video Tutorial included!) #csharp #nodejs #dotnet #async

I have been working a couple of days on Node.Net. A Node.JS alternative that uses the brand new features from .NET 4.5


Put the video at 720p and full screen to watch it fine.

Project: https://github.com/soywiz/nodenet

What's the point on making a Node.JS clone?

Node.JS has several problems that won't be solved:
  • Fully dynamic typing (IDEs can't make a good work on autocompleting) and you would end working without autocompleting at all, and detecting errors when executing and not while coding.
  • There is no great IDEs for javascript
  • The flow is event-driven
  • Javascript don't support real classes, and lacks lots of programming features
  • The way you should extend javascript is problemating (.NET's extension methods are much better)
  • Spreading exceptions is a pain and you can't between async methods
What offers Node.NET?

Node.NET works with any .NET language and even when it presents the problem that allows to to make async wrong, the IDE helps you to doing it right as you can see in the video below.

  • .NET and VS11 offeres the best static typing out there
  • Has lots of very powerful APIs
  • It's a modern OO programming language with all the stuff you could expect and like: operator overloading, class inheritance, extension methods, LINQ, events, dynamic support...
  • Visual Studio Express is free, and you can use MonoDevelop too
  • The async/await model converts asynchronous methods into very efficient machine states when executing.
  • Allows you to create async code with a sequential look and flow
  • Allows you to use try/catch with async methods, so you can spread exceptions in an easy way
  • All the .NET advantages and it's great speed
  • It can work on linux and make using Mono >= 2.12 that already supports .NET 4.5
Hello World Http using Node.JS:

var http = require('http');

http.createServer(function (request, response) {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.write('Hello World\n', function() {
  response.end('');
  });
}).listen(8124);

ab -n 10000 -c 200 http://127.0.0.1:8124/test
Requests per second:    7644.83 [#/sec] (mean)

Hello World Http using Node.Net:

await HttpServer.Create(async (Request, Response) =>
{
  Response.Buffering = true;

  Response.Code = 200;
  Response.Headers["Content-Type"] = "text/plain";
  await Response.WriteChunkAsync("Hello World!");
  await Response.WriteChunkAsync("");
}).ListenAsync(80);

ab -n 10000 -c 200 http://127.0.0.1:8124/test 
Requests per second:    8374.73 [#/sec] (mean)

Notice that while debugging using Visual Studio the RPS will be about 1000 as much. That's normal because the debug execution is much slower. When launching as a normal executable, RPS will achieve those values.