March 17, 2010

SWF Machine is an Erlang program I’ve been writing, to generate SWF files from Erlang. This program takes a custom instruction set as input and generates SWF binary instructions, which once saved in an SWF file can be run in the Flash Player, here’s a quick demo of SWFMachine in action …

A similar attempt by Takashi Yamamiya and the eswf library on google code were quite helpful in getting me started, so thanks to them for sharing.

February 12, 2010

Over the last few weeks I’ve been writing a server side web application framework for Erlang. Essentially, I looked at various available erlang frameworks like WebMachine, Nitrogen, BeepBeep, Yaws, ErlyWeb etc. and pulled out and assembled my own little framework with features I needed. I’ve also been writing an Erlang library for encoding/decoding AMF which will help me add some interesting Flash/Flex specific features to this framework.

Among other things this framework provides web server library specific request/response format abstraction similar to SimpleBridge, A Django templates implementation using ErlyDTL, an MVC implementation inspired from ErlyWeb and a lot more. Even with all this functionality I’m quite happy with the performance we’re able to achieve, so I thought I’d share some benchmarks with everyone.

Since the framework completely abstracts out the web server library used, I was able to try out various web options, but I think we’ll stick with Misultin for our production enviornment since it seems to perform significantly better than other implementations. Here are the results of running AutoBench on our framework powered by Misultin.

The server was running on an m1.large amazon instance running ubuntu and the tests was run from an m1.small amazon instance.


$ autobench --single_host --host1 xyz.com --quiet --low_rate 20 --high_rate 200 --rate_step 20 --num_call 100 -num_conn 5000 --timeout 5 --file results.tsv

Misultin-Autobench
read more

November 28, 2009

I’ve been learning Erlang for the past few weeks and loving the simplicity and beauty of the language. As part of a discussion at SAP TechEd, last week, I ended up creating a simple, rather rudimentary prototype of a realtime messaging server that enables collaborative user interfaces where multiple users can simultaneously work with the same interface …

Here’s a video of the code in action …

As you watch the above video, note as I drag a rectangle in any one Flash application, its sends AMF encoded binary messages to the server and the server multicasts these messages to other connected clients and those clients update in almost realtime. While in the example above all the application instances are running on the same system, they could just as easily be running on different systems and still communicate via the server.

Here the code for the Erlang server …

0001 -module(server).
0002 -export([start/1,stop/0]).
0003 
0004 -define(TCP_OPTIONS,[binary,
0005                      {packet, 0},
0006                      {active, false},
0007                      {reuseaddr, true}]).
0008 
0009 start(Port) ->
0010 	 Pid = spawn(fun() -> manage([]) end),
0011     register(client_manager, Pid),
0012 	 {ok, Socket} = gen_tcp:listen(Port, ?TCP_OPTIONS),
0013     accept(Socket).
0014 
0015 stop() -> todo.
0016 
0017 accept(Socket) ->
0018   	 {ok, NewSocket} = gen_tcp:accept(Socket),
0019     spawn(fun() -> recieve(NewSocket) end),
0020     client_manager ! {connected, NewSocket},
0021     accept(Socket).
0022 
0023 recieve(Socket) ->
0024     case gen_tcp:recv(Socket, 0) of
0025         {ok, Data} ->
0026             client_manager ! {multicast,Socket,Data},
0027             recieve(Socket);
0028         {error, closed} ->
0029  		 client_manager ! {disconnect, Socket}
0030     end.
0031 
0032 manage(Sockets) ->
0033     receive
0034         {connected, Socket} ->
0035             NewSockets = [Socket | Sockets];
0036         {disconnected, Socket} ->
0037             NewSockets = lists:delete(Socket, Sockets);
0038         {multicast,Socket, Data} ->
0039             multicast(Socket, Sockets, Data),
0040             NewSockets = Sockets
0041     end,
0042     manage(NewSockets).
0043 
0044 multicast(FromSocket, ToSockets, Data) ->
0045     SendData = fun(Socket) -> gen_tcp:send(Socket, Data) end,
0046     Sockets = [ S || S <- ToSockets, S /= FromSocket],
0047     lists:foreach(SendData, Sockets).