Posted on 2007-04-04 12:09
小蚂蚁 阅读(783)
评论(0) 编辑 收藏 所属分类:
FreeBSD
用spca5xx做的Livecam通过CGI在lighttpd下实现总有个问题:client网速慢的时候lighttpd的内存用量会不断增加,一直到把系统榨干,没办法硬着头皮看lighttpd的mod_cgi源码,通过分析发现:
while(1) {
int n;
buffer_prepare_copy(hctx->response, 1024);
if (-1 == (n = read(hctx->fd, hctx->response->ptr, hctx->response->size - 1))) {
if (errno == EAGAIN || errno == EINTR) {
/* would block, wait for signal */
return FDEVENT_HANDLED_NOT_FINISHED;
}
......
} else {
http_chunk_append_mem(srv, con, hctx->response->ptr, hctx->response->used);
joblist_append(srv, con);
}
mod_cgi通过hctx->fd从cgi读取数据,然后由http_chunk_append_men()提交到后台,但chunk_append却没有限制内存的使用,当从cgi读取的速度快过提交给client速度时内存用量就会不断增加。本来想通过signal来同步cgi的采样,但这样太麻烦而且会破坏mod_cgi的结构,试着在read(hctx->fd...前加个阻塞判断:
if (http_chunkqueue_length(server *srv, connection *con) > 102400) {
return FDEVENT_HANDLED_NOT_FINISHED;
}
if (-1==(n=read(hctx->fd...
然后在spca5shot里每采样一frame加个sleep(1),运行几天看效果再说