Using pre-release versions of Go 1.2, it was able to serve over 500,000 concurrent users from each physical host without special tuningтюненный ерланг там бы сервил 10М, но твитч не умеет писать на нем
-module(sample).
-behaviour(supervisor).
-behaviour(application).
-export([init/1, start/2, stop/1, main/1]).
start(_,_) -> supervisor:start_link({local,review},review,[]).
stop(_) -> ok.
init([]) -> case cowboy:start_http(http,3,port(),env()) of
{ok, _} -> ok;
{error,_} -> halt(abort,[]) end, sup().
sup() -> { ok, { { one_for_one, 5, 100 }, [] } }.
port() -> [ { port, application:get_env(n2o,port,8000) } ].
env() -> [ { env, [ { dispatch, points() } ] } ].
static() -> { dir, "apps/sample/priv/static", mime() }.
n2o() -> { dir, "deps/n2o/priv", mime() }.
mime() -> [ { mimetypes, cow_mimetypes, all } ].
points() -> cowboy_router:compile([{'_', [
{ "/static/[...]", n2o_static, static()},
{ "/n2o/[...]", n2o_static, n2o()},
{ "/ws/[...]", n2o_stream, []},
{ '_', n2o_cowboy, []} ]}]).
pickle(Data) ->
Message = term_to_binary({Data,now()}),
Padding = size(Message) rem 16,
Bits = (16-Padding)*8, Key = secret(), IV = crypto:rand_bytes(16),
Cipher = crypto:block_encrypt(aes_cbc128,Key,IV,<<Message/binary,0:Bits>>),
Signature = crypto:hmac(sha256,Key,<<Cipher/binary,IV/binary>>),
base64:encode(<<IV/binary,Signature/binary,Cipher/binary>>).
secret() -> wf:config(n2o,secret,<<"ThisIsClassified">>).
depickle(PickledData) ->
try Key = secret(),
Decoded = base64:decode(wf:to_binary(PickledData)),
<<IV:16/binary,Signature:32/binary,Cipher/binary>> = Decoded,
Signature = crypto:hmac(sha256,Key,<<Cipher/binary,IV/binary>>),
{Data,_Time} = binary_to_term(crypto:block_decrypt(aes_cbc128,Key,IV,Cipher),[safe]),
Data
catch E:R -> wf:info(?MODULE,"Depicke Error: ~p",[{E,R}]), undefined end.
$ wrk -c 50 -r 50 -t 4 -k http://localhost:8001/
Making 50 requests to http://localhost:8001/
4 threads and 50 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 162.69ms 483.80ms 1.69s 89.58%
Req/Sec 0.00 0.00 0.00 100.00%
48 requests, 48 sock connections in 1.75s, 47.53KB read
Requests/sec: 27.42
Transfer/sec: 27.15KB
server {
listen 80;
server_name example.com;
return 301 https://$server_name$request_uri; # enforce https
# rewrite ^(.*) https://www.example.com$uri permanent;
}