nginx module memory problem
김영진
yjkim2040 at gmail.com
Thu Oct 4 05:13:17 UTC 2012
hi, i am web server(nginx) module developer.
my nginx modules has a major problem.
maybe... this problem is seem to nginx core bug.
i hope this is my module problem. Because, i wish the problem to be settled
soon.
*my module function:*
large post data logging from specified file(nginx.conf setting :
/home1/test_access.log)
*problem:*
constant use of memory(nginx-1.2.2 , same situation)
[image: 본문 이미지 1]
*nginx environment:*
./nginx -V
nginx version: nginx/1.0.14
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-44)
configure arguments: --prefix=/home1/apps/nginx
--with-http_gzip_static_module --with-http_stub_status_module
--add-module=/home1/apps/nginx-1.0.14/modules*/testmodule*
**
*server environment:*
uname -a
Linux test.server 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64
x86_64 x86_64 GNU/Linux
*/etc/redhat-release:*
CentOS release 5.3 (Final)
*nginx.conf:*
worker_processes 2;
worker_cpu_affinity 01 10;
worker_rlimit_core 500M;
working_directory /home1/cores/;
worker_rlimit_nofile 15000;
...
events {
worker_connections 15000;
accept_mutex on;
}
...
http {
client_body_in_single_buffer on;
client_body_in_file_only off;
client_body_buffer_size 10m;
client_max_body_size 10m;
client_header_buffer_size 10m;
server {
listen 80;
server_name test.test.com;
location = /test {
testaccess_log /home1/test_access.log;
...
}
...
}
}
...
* my module source code :*
static int ngx_testmodule_log_write(ngx_http_request_t *r, char * content,
unsigned int content_size)
{
this function is file writting...
}
void
ngx_testmodule_post_read_request_body(ngx_http_request_t *r)
{
ngx_int_t totalreadsize;
ngx_int_t movepos;
ngx_chain_t * cl=NULL;
ngx_chain_t * cl2=NULL;
ngx_buf_t * buf=NULL;
char * container=NULL;
ngx_http_testmodule_conf_t * pConfig = NULL;
int split_returnvalue;
pConfig = ngx_http_get_module_loc_conf(r, ngx_http_testmodule_module);
if(r->request_body == NULL || r->request_body->bufs == NULL ||
r->request_body->bufs->buf == NULL)
{
ngx_http_finalize_request(r, NGX_DONE);
return;
}
cl = r->request_body->bufs;
if(cl->next == NULL)
{
buf = cl->buf;
totalreadsize = buf->last-buf->pos;
if(totalreadsize > 0)
{
container = (char *)ngx_pcalloc(r->pool, totalreadsize+1);
if(container == NULL)
{
ngx_http_finalize_request(r, NGX_DONE);
return;
}
memcpy(container, (char *)buf->pos, buf->last-buf->pos);
*(container+(buf->last-buf->pos)) = '\0';
}
else
{
ngx_http_finalize_request(r, NGX_DONE);
return;
}
}
else
{
fprintf(stderr, "=====MULTI BUFFER=====\n");
totalreadsize = 0;
cl2 = cl;
while(cl2)
{
totalreadsize += cl2->buf->last - cl2->buf->pos;
cl2 = cl2->next;
}
if(totalreadsize > 0)
{
container = (char *)ngx_pcalloc(r->pool, totalreadsize+1);
if(container == NULL)
{
ngx_http_finalize_request(r, NGX_DONE);
return;
}
movepos = 0;
while(cl)
{
memcpy(container + movepos, (char *)cl->buf->pos, cl->buf->last -
cl->buf->pos);
movepos += (cl->buf->last - cl->buf->pos);
cl = cl->next;
}
*(container + movepos) = '\0';
}
else
{
ngx_http_finalize_request(r, NGX_DONE);
return;
}
if(totalreadsize != movepos)
{
ngx_http_finalize_request(r, NGX_DONE);
return;
}
}
split_returnvalue = ngx_testmodule_log_write(r, container, totalreadsize);
ngx_http_finalize_request(r, NGX_DONE);
return;
}
ngx_http_testmodule_handler(ngx_http_request_t *r)
{
if (!(r->method & NGX_HTTP_POST)) {
return NGX_HTTP_NOT_ALLOWED;
}
else if(!pConfig->enable) {
return NGX_DECLINED;
}
rc_post = ngx_http_read_client_request_body(r,
ngx_testmodule_post_read_request_body);
ngx_testmodule_resheader(r);
...
return ngx_http_send_response(r, NGX_HTTP_OK, &ngx_http_text_type, &cv);
}
i have tested my nginx module. but... i don't know.. difficult problem..
i am turning to you for help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20121004/145aee81/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: memory.jpg
Type: image/jpeg
Size: 21406 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20121004/145aee81/attachment-0001.jpg>
More information about the nginx-devel
mailing list