High Load configuration question

Tronman nginx-forum at nginx.us
Mon Jan 11 18:28:15 MSK 2010

Hi there,

Thanks for your response, sorry it took me so long to reply.

> 1. On FreeBSD you can try to increase kern.ipc.somaxconn. I bet 8192
> would be enough for your test. This is socket backbuffer which can cache
> connections before server actually accepts them

Currently, the OS I'm running on is Ubuntu 9.10, single core Intel with 1024 MB ram. But if I try a sysctl kern.ipc.somaxconn, it comes up as unknown key.

> 2. Try shed some light on your module internals. Right now I can only
> say that you certainly messed something inside main loop but can't tell
> you what and why.

Here's the basics of the module, you can also use a usleep simply to slow things down, but I get time out errors even without that, and some simple output sent. Note that I do a ngx_http_read_client_request_body because I need access to the post body.


static char* ngx_http_my_module(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static ngx_int_t ngx_http_my_module_handler(ngx_http_request_t *r);

static ngx_command_t  ngx_http_my_module_init_commands[] = {
    { ngx_string("my_module"),
      NULL },

ngx_http_module_t  ngx_http_my_module_module_ctx = {
    NULL,                                  /* preconfiguration */
    NULL,                                  /* postconfiguration */

    NULL,                                  /* create main configuration */
    NULL,                                  /* init main configuration */

    NULL,                                  /* create server configuration */
    NULL,                                  /* merge server configuration */

    NULL,                                  /* create location configuration */
    NULL                                   /* merge location configuration */

ngx_module_t  ngx_http_my_module_module = {
    &ngx_http_my_module_module_ctx,           /* module context */
    ngx_http_my_module_init_commands,        /* module directives */
    NGX_HTTP_MODULE,                       /* module type */
    NULL,                                  /* init master */
    NULL,                                  /* init module */
    NULL,                                  /* init process */
    NULL,                                  /* init thread */
    NULL,                                  /* exit thread */
    NULL,                                  /* exit process */
    NULL,                                  /* exit master */

static void
ngx_http_my_module_post_handler(ngx_http_request_t *r);

static ngx_int_t
ngx_http_my_module_handler(ngx_http_request_t *r)

    int rc;
    rc = ngx_http_read_client_request_body(r, ngx_http_my_module_post_handler);

	return rc;
    return NGX_DONE;

static void
ngx_http_my_module_post_handler(ngx_http_request_t *r)
      int header_rc, rc;
    ngx_chain_t   *outputChain;  
    outputChain = ngx_pcalloc(r->pool, sizeof(ngx_chain_t));  

    outputChain->buf = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
    outputChain->buf->pos = ngx_palloc(r->pool, 8);
    outputChain->buf->start = outputChain->buf->pos;
    outputChain->buf->memory = 1;
    outputChain->buf->last_buf = 1;
    ngx_memcpy(outputChain->buf->pos, "Testing", 7);
    outputChain->buf->pos[7] = '\0';
    outputChain->buf->last = outputChain->buf->pos + 7;	

    r->headers_out.content_length_n = 7;
    r->headers_out.content_type.len = sizeof("text/plain") - 1;
    r->headers_out.content_type.data = (u_char *) "text/plain";
    r->headers_out.status = NGX_HTTP_OK;

    header_rc = ngx_http_send_header(r);
    rc = ngx_http_output_filter(r, outputChain);
    ngx_http_finalize_request(r, rc);  

static char *
ngx_http_my_module(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)

       ngx_http_core_loc_conf_t  *clcf;
    clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
    clcf->handler = ngx_http_my_module_handler;

    return NGX_CONF_OK;

My nginx.conf file has:

worker_processes  1;
worker_connections  1024;

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;

    server {
        listen       80;
        server_name  localhost;

	location /somefile.html {

Running curl-loader against that module, I can get around 3000/requests per second, but with Connection Time out errors.

However, if I copy and paste that same code into the "static" module (simply change my_module to static), and run it, I get around 6000/requests per second and with NO connection time out errors. 

So how and why is my module being treated any differently then the static module? I don't see why mine can't run at the same speed as it, even where there code is pretty much a copy and paste of one another, and the configurations/systems are identical? I can add usleeps to the static module and get time outs, but my module seems to get them even without it.

If it helps too, the connection time outs are usually in long blocks, e.g. 20000 ok's followed by 50 time outs, followed by thousand more okay's, etc....


Posted at Nginx Forum: http://forum.nginx.org/read.php?2,38810,39779#msg-39779

More information about the nginx mailing list