• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

jeremycw/httpserver.h: Single header library for writing non-blocking HTTP serve ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

jeremycw/httpserver.h

开源软件地址:

https://github.com/jeremycw/httpserver.h

开源编程语言:

C 94.4%

开源软件介绍:

Build Status

See httpserver.h for API documentation

Description

httpserver.h is a single header C library for building event driven non-blocking HTTP servers

Supports Linux with epoll and BSD/Mac with kqueue.

Example

#define HTTPSERVER_IMPL
#include "httpserver.h"

#define RESPONSE "Hello, World!"

void handle_request(struct http_request_s* request) {
  struct http_response_s* response = http_response_init();
  http_response_status(response, 200);
  http_response_header(response, "Content-Type", "text/plain");
  http_response_body(response, RESPONSE, sizeof(RESPONSE) - 1);
  http_respond(request, response);
}

int main() {
  struct http_server_s* server = http_server_init(8080, handle_request);
  http_server_listen(server);
}

See full documentation in httpserver.h

Benchmark

I ran some micro-benchmarks with httpserver.h and NGINX serving a simple Hello, World! The purpose here was just to get a performance reference point, not to try and make any statement of superiority since httpserver.h is not a competitor or replacement for NGINX.

With keep-alive

ab -k -c 200 -n 100000 http://localhost:8080/

NGINX 74441.26 requests/sec

Server Software:        nginx/1.14.0
Server Hostname:        localhost
Server Port:            8000

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      200
Time taken for tests:   1.343 seconds
Complete requests:      100000
Failed requests:        0
Keep-Alive requests:    99052
Total transferred:      20995260 bytes
HTML transferred:       1300000 bytes
Requests per second:    74441.26 [#/sec] (mean)
Time per request:       2.687 [ms] (mean)
Time per request:       0.013 [ms] (mean, across all concurrent requests)
Transfer rate:          15262.83 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0  17.8      0    1029
Processing:     0    2   8.8      1     148
Waiting:        0    2   8.8      1     148
Total:          0    3  21.4      1    1150

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      2
  75%      2
  80%      2
  90%      2
  95%      2
  98%      3
  99%     35
 100%   1150 (longest request)

httpserver.h 123907.91 requests/sec

Server Software:        
Server Hostname:        localhost
Server Port:            8080

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      200
Time taken for tests:   0.807 seconds
Complete requests:      100000
Failed requests:        0
Keep-Alive requests:    100000
Total transferred:      13400000 bytes
HTML transferred:       1300000 bytes
Requests per second:    123907.91 [#/sec] (mean)
Time per request:       1.614 [ms] (mean)
Time per request:       0.008 [ms] (mean, across all concurrent requests)
Transfer rate:          16214.51 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       4
Processing:     1    2   0.3      2       6
Waiting:        1    2   0.3      2       6
Total:          1    2   0.4      2       6

Percentage of the requests served within a certain time (ms)
  50%      2
  66%      2
  75%      2
  80%      2
  90%      2
  95%      2
  98%      3
  99%      3
 100%      6 (longest request)

With Connection: close

ab -c 200 -n 100000 http://localhost:8080/

NGINX 15773.47 requests/sec

Server Software:        nginx/1.14.0
Server Hostname:        localhost
Server Port:            8000

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      200
Time taken for tests:   6.340 seconds
Complete requests:      100000
Failed requests:        0
Total transferred:      20500000 bytes
HTML transferred:       1300000 bytes
Requests per second:    15773.47 [#/sec] (mean)
Time per request:       12.680 [ms] (mean)
Time per request:       0.063 [ms] (mean, across all concurrent requests)
Transfer rate:          3157.77 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    4  40.6      3    1123
Processing:     1    8  46.7      4     508
Waiting:        1    7  46.7      3     508
Total:          3   12  64.5      6    1460

Percentage of the requests served within a certain time (ms)
  50%      6
  66%      7
  75%      7
  80%      8
  90%      8
  95%      9
  98%     10
  99%    503
 100%   1460 (longest request)

httpserver.h 27605.45 requests/sec

Server Software:        
Server Hostname:        localhost
Server Port:            8080

Document Path:          /
Document Length:        13 bytes

Concurrency Level:      200
Time taken for tests:   3.622 seconds
Complete requests:      100000
Failed requests:        0
Total transferred:      12900000 bytes
HTML transferred:       1300000 bytes
Requests per second:    27605.45 [#/sec] (mean)
Time per request:       7.245 [ms] (mean)
Time per request:       0.036 [ms] (mean, across all concurrent requests)
Transfer rate:          3477.64 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        2    3   0.5      3       6
Processing:     1    4   0.7      4       8
Waiting:        1    3   0.8      3       7
Total:          4    7   0.6      7      11

Percentage of the requests served within a certain time (ms)
  50%      7
  66%      7
  75%      8
  80%      8
  90%      8
  95%      8
  98%      9
  99%      9
 100%     11 (longest request)

NGINX conf

worker_processes 1;

http {
    server {
        listen 8000;
        location / {
             add_header Content-Type text/plain;
             return 200 'Hello, World!';
        }
    }
}



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
ava/use-http: 发布时间:2022-06-17
下一篇:
lyxhh/lxhToolHTTPDecrypt: Simple Android/iOS protocol analysis and utilization t ...发布时间:2022-06-17
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap