Skip to content

Instantly share code, notes, and snippets.

@kjmkznr
Last active July 18, 2016 17:58
Show Gist options
  • Save kjmkznr/a373f08b51fde9463d54 to your computer and use it in GitHub Desktop.
Save kjmkznr/a373f08b51fde9463d54 to your computer and use it in GitHub Desktop.
using lwan from golang

benchmark result

EC2 m3.medium / Gentoo Linux

go version go1.3.3 linux/amd64

$ ./wrk http://localhost:8081/hello
Running 10s test @ http://localhost:8081/hello
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    65.09ms  290.77ms   1.37s    95.27%
    Req/Sec    10.86k     7.99k   48.33k    69.01%
  190614 requests in 10.00s, 34.90MB read
Requests/sec:  19059.57
Transfer/sec:      3.49MB

nginx 1.7.6

wrk

Running 10s test @ http://localhost/
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    12.96ms   28.57ms  82.00ms   85.19%
    Req/Sec     9.33k     9.14k   40.78k    82.52%
  158301 requests in 10.00s, 40.11MB read
Requests/sec:  15830.41
Transfer/sec:      4.01MB

nginx.conf

user nginx nginx;
worker_processes 1;

error_log /var/log/nginx/error_log info;

events {
        worker_connections 1024;
        use epoll;
}

http {
        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        log_format main
                '$remote_addr - $remote_user [$time_local] '
                '"$request" $status $bytes_sent '
                '"$http_referer" "$http_user_agent" ';
        access_log  none;

        server_tokens off;


        client_header_timeout 10m;
        client_body_timeout 10m;
        send_timeout 10m;

        connection_pool_size 256;
        client_header_buffer_size 1k;
        large_client_header_buffers 4 2k;
        request_pool_size 4k;

        output_buffers 1 32k;
        postpone_output 1460;

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;

        open_file_cache max=100000 inactive=60s;
        open_file_cache_valid 60s;
        open_file_cache_min_uses 2;
        open_file_cache_errors on;

        keepalive_timeout 75 20;
        ignore_invalid_headers on;
        index index.html;
        server {
                listen 127.0.0.1;
                server_name localhost;
                error_log /var/log/nginx/localhost.error_log info;
                root /var/www/localhost/htdocs;
        }
}
listener *:8081 {
prefix /hello {
handler = helloworld
}
}
package main
/*
#cgo LDFLAGS: -lpthread -ldl -lz common/liblwan-common.a
#include "common/lwan.h"
#include <stdlib.h>
typedef struct _Void {
void *data;
} Void;
*/
import "C"
import "unsafe"
type Void C.Void
var content_type = C.CString("text/plain")
func main() {
var l C.lwan_t
C.lwan_init(&l)
C.lwan_main_loop(&l)
C.lwan_shutdown(&l)
}
//export helloworld
func helloworld(request *C.lwan_request_t, response *C.lwan_response_t, data *Void) C.lwan_http_status_t {
response.mime_type = content_type
message := "Hello, World!"
message_char := C.CString(message)
defer C.free(unsafe.Pointer(message_char))
C.strbuf_set(response.buffer, message_char, C.size_t(len(message)-1))
return C.HTTP_OK
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment