zyearn / zaver Goto Github PK
View Code? Open in Web Editor NEWYet another fast and efficient HTTP server
License: MIT License
Yet another fast and efficient HTTP server
License: MIT License
Line 50 in 2f43059
我查阅了nginx源码,它不光包含下划线,还包含中划线。
HTTP 方法中不都是大写字母吗?疑惑中。。。
在 zaver.c 的 58line 的 while循环中 case ': ' ,这个看不懂,
while ((opt=getopt_long(argc, argv,"Vc:?h",long_options,&options_index)) != EOF) {
switch (opt) {
case 0 : break;
case 'c':
conf_file = optarg;
break;
case 'V':
printf(PROGRAM_VERSION"\n");
return 0;
case ':':
case 'h':
case '?':
usage();
return 0;
}
}
man getopt-long 上说,c: 代表 c需要一个参数,
博主你怎么看
I would like to point out that identifiers like "__list_add
" and "_THREADPOOL_H
" do not fit to the expected naming convention of the C language standard.
Would you like to adjust your selection for unique names?
pthread_mutex_t lock;
pthread_cond_t cond;
https://github.com/zyearn/zaver/blob/master/src/threadpool.h#L29-L30
线程池结构中只有一对互斥锁和条件变量,生产者线程每添加一个新任务,都会调用 pthread_cond_signal 一次,所有线程都会等待同一个cond
, 但最终只有一个消费者线程从队列里拿到任务去执行,其他线程被唤醒带来不必要的线程调度开销,这就是惊群现象的根源所在,并且是消费者线程数量越多,惊群现象越严重----意味着 CPU 占用越高,线程池的调度性能越低。
一个解决方法是,在共用同一个互斥锁情况下,给每一个消费者线程创建对应的线程条件变量,这样生产者线程有新任务并找到空闲消费者线程时候,将任务添加到队列中并只通知该消费者线程。线程条件变量的通知过程是定向的,未被通知的消费者线程不会被唤醒,这样惊群现象也就不会产生了。
192到227行处,于202和205行处可跳出循环,而跳出循环前已经unlock了,而224行处再次进行unlock是未定义行为,且210处的continue,会导致未对本次循环lock进行unlock,而继续对下次循环进行lock从而导致死锁。
It seems that your list_add_tail implementation is the same as list_add and differs from linux kernel implementation.
十分感谢开源了这个Http服务器,我打算作为学习材料来学习,能否指导一下阅读源代码的框架顺序或者思路?
感激不尽 :)
I suggest to reuse a higher level build system than your current small make file so that powerful checks for software features will become easier.
[ERROR] (/home/wiltjames/Desktop/Code/zaver-master/src/util.c:60: errno: Bad file descriptor) fcntl
[ERROR] (/home/wiltjames/Desktop/Code/zaver-master/src/zaver.c:117: errno: Bad file descriptor) make_socket_non_blocking
[ERROR] (/home/wiltjames/Desktop/Code/zaver-master/src/epoll.c:23: errno: Bad file descriptor) zv_epoll_add: epoll_ctl
请问为什么运行时会出现这些错误?
threadpool.c中,41-45行中,为什么条件变量初始化失败后,要先对lock加锁后再destroy,根据“http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_mutex_destroy.html”,
加锁后未释放锁是未定义行为。
你主页中的线程池的使用都注释了,是线程池没做好吗?
Would you like to add more error handling for return values from functions like the following?
threadpool.c 中27-35行处,应 pool->head = (zv_task_t *)malloc(sizeof(zv_task_t));后立即检查pool->head == NULL条件,33行处的检查没有意义。
Line 177 in 955eba0
让infd不阻塞是什么意思呢,认为应该是listenfd,或是我理解错了。
楼下说分片处理的情况, 我觉得不存在, 因为只能get啊...
假设对方请求数据过大,或你的可接受MTU单元过小,数据被分片发送,恰好只到了一部分数据,你读取了,你的程序似乎不能正确处理。而且这很常见
1 if ((pool = (zv_threadpool_t *)malloc(sizeof(zv_threadpool_t))) == NULL){ goto err; }
动态申请pool的内存为什么没有释放?
2 if (pool->shutdown == immediate_shutdown) { break; } else if ((pool->shutdown == graceful_shutdown) && pool->queue_size == 0) { break; }
这里的意思是区别对待2种销毁线程池的方式.选择graceful_shutdown的方式是: 等执行完任务队列所有任务时所有线程再一起退出吗.?
我的意思是假设现在有最后一个任务,线程池里有3个线程,那么有1个线程在执行任务,另外2个在阻塞.
好,现在选择graceful_shutdown销毁线程池,有任务的线程会继续执行, 阻塞的被broad唤醒然后会再再次
cond_wait. 然后再被唤醒(因为前面是do_while),
以上,不知道我的理解对不对?
3 if (task == NULL) { pthread_mutex_unlock(&(pool->lock)); continue; }
在static void *threadpool_worker(void *arg)中加这几行代码是为什么呢?
希望博主赐教. thx.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.