Code Monkey home page Code Monkey logo

zaver's Introduction

Zaver

Yet another fast and efficient HTTP server.

purpose

The purpose of Zaver is to help developers understand how to write a high performance server based on epoll. Although Nginx is a good learning example, its complexity and huge code base make people discouraged. Zaver uses as few codes as possible to demonstrate the core structure of high performance server like Nginx. Developers can lay a solid foundation by learning Zaver for further study in network programming.

programming model

  • epoll
  • non-blocking I/O
  • thread-pool

compile and run (for now only support Linux2.6+)

please make sure you have cmake installed.

mkdir build && cd build
cmake .. && make
cd .. && ./build/zaver -c zaver.conf

support

  • HTTP persistent connection
  • browser cache
  • timer(use binary heap instead of rbtree used in Nginx)

todo

  • sendfile
  • proxy
  • FastCGI
  • other HTTP/1.1 features
  • memory pool
  • WebDAV?

more details

https://zyearn.github.io/blog/2015/05/16/how-to-write-a-server/

zaver's People

Contributors

itmox avatar timgates42 avatar zyearn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zaver's Issues

list_add_tail implementation

It seems that your list_add_tail implementation is the same as list_add and differs from linux kernel implementation.

threadpool.c 存在死锁问题

192到227行处,于202和205行处可跳出循环,而跳出循环前已经unlock了,而224行处再次进行unlock是未定义行为,且210处的continue,会导致未对本次循环lock进行unlock,而继续对下次循环进行lock从而导致死锁。

看不懂

在 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需要一个参数,
博主你怎么看

线程池“惊群”现象

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 占用越高,线程池的调度性能越低。

一个解决方法是,在共用同一个互斥锁情况下,给每一个消费者线程创建对应的线程条件变量,这样生产者线程有新任务并找到空闲消费者线程时候,将任务添加到队列中并只通知该消费者线程。线程条件变量的通知过程是定向的,未被通知的消费者线程不会被唤醒,这样惊群现象也就不会产生了。

你考虑过TCP分片了吗

假设对方请求数据过大,或你的可接受MTU单元过小,数据被分片发送,恰好只到了一部分数据,你读取了,你的程序似乎不能正确处理。而且这很常见

运行错误

[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
请问为什么运行时会出现这些错误?

线程池疑惑?

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.

Serious vulnerability exists

Directory traversal.

Hackers can gain access to a wealth of sensitive information including configuration files.

image

For example, here I can read my .bashrc and zaver.conf

image

pool->head == NULL 检查位置错误

threadpool.c 中27-35行处,应 pool->head = (zv_task_t *)malloc(sizeof(zv_task_t));后立即检查pool->head == NULL条件,33行处的检查没有意义。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.