Welcome! Log In Create A New Profile

Advanced

Re: High Load configuration question

January 11, 2010 10:28AM
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.

[code]
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>

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"),
NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
ngx_http_my_module,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },
ngx_null_command
};

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_MODULE_V1,
&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 */
NGX_MODULE_V1_PADDING
};

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);

if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
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);

return;
}

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;
}
[/code]

My nginx.conf file has:


[code]
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 {
my_module;
}
}
}
[/code]

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....

Thanks!
Subject Author Posted

High Load configuration question

Tronman January 08, 2010 04:08PM

Re: High Load configuration question

Piotr Sikora January 08, 2010 05:24PM

Re: High Load configuration question

Tronman January 08, 2010 05:33PM

Re: High Load configuration question

Piotr Sikora January 08, 2010 06:14PM

Re: High Load configuration question

Volodymyr Kostyrko January 08, 2010 06:00PM

Re: High Load configuration question

Tronman January 11, 2010 10:28AM

Re: High Load configuration question

Tronman January 11, 2010 10:35AM

Re: High Load configuration question

Tronman January 11, 2010 11:32AM

Re: High Load configuration question

Tronman January 11, 2010 01:58PM

Re: High Load configuration question

Volodymyr Kostyrko January 16, 2010 03:44PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 73
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready