Code Monkey home page Code Monkey logo

http-server's Introduction

http-server

A fast http server written in C.

Usage

$ ./http-server

Requirements

Installation

$ mkdir build && cd build && cmake .. && make

Benchmark

$ ab -k -c 10 -n 10000 http://127.0.0.1:7000/

Linux(Xeon 1.80GHz)

Server Software:
Server Hostname:        127.0.0.1
Server Port:            7000

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      100
Time taken for tests:   3.981 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100000
Total transferred:      10002540 bytes
HTML transferred:       1200252 bytes
Requests per second:    25121.37 [#/sec] (mean)
Time per request:       3.981 [ms] (mean)
Time per request:       0.040 [ms] (mean, across all concurrent requests)
Transfer rate:          2453.88 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       7
Processing:     2    4   0.5      4       7
Waiting:        2    3   0.6      3       6
Total:          3    4   0.6      4      10

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

Windows(Intel Core i5/3Hz)

Server Software:
Server Hostname:        localhost
Server Port:            7000

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      40
Time taken for tests:   5.130513 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100000
Total transferred:      10001004 bytes
HTML transferred:       1200036 bytes
Requests per second:    19491.23 [#/sec] (mean)
Time per request:       2.052 [ms] (mean)
Time per request:       0.051 [ms] (mean, across all concurrent requests)
Transfer rate:          1903.51 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:     1    2   0.3      2      11
Waiting:        0    1   0.7      1      11
Total:          1    2   0.3      2      12

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

Linux(Intel Core i5/3Hz)

Server Software:        
Server Hostname:        127.0.0.1
Server Port:            7000

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      10
Time taken for tests:   0.310 seconds
Complete requests:      10000
Failed requests:        0
Keep-Alive requests:    10000
Total transferred:      1000000 bytes
HTML transferred:       120000 bytes
Requests per second:    32291.29 [#/sec] (mean)
Time per request:       0.310 [ms] (mean)
Time per request:       0.031 [ms] (mean, across all concurrent requests)
Transfer rate:          3153.45 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:     0    0   0.2      0       5
Waiting:        0    0   0.1      0       5
Total:          0    0   0.2      0       5

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

License

MIT

Author

Yasuhiro Matsumoto (a.k.a mattn)

http-server's People

Contributors

i5ting avatar mattn 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

http-server's Issues

mac compile issue

➜ http-server git:(master) mkdir build && cd build && cmake .. && make
-- The C compiler identification is AppleClang 6.0.0.6000051
-- The CXX compiler identification is AppleClang 6.0.0.6000051
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/sang/workspace/github/http-server/build
Scanning dependencies of target http-server
[ 33%] Building C object CMakeFiles/http-server.dir/server.c.o
/Users/sang/workspace/github/http-server/server.c:128:58: error: passing 'int' to parameter of incompatible type 'uv_err_t' (aka 'struct uv_err_s')
fprintf(stderr, "Write error: %s: %s\n", uv_err_name(status), uv_strerror(status));
^~~~~~
/usr/local/include/uv.h:426:44: note: passing argument to parameter 'err' here
UV_EXTERN const char* uv_err_name(uv_err_t err);
^
/Users/sang/workspace/github/http-server/server.c:140:62: error: passing 'int' to parameter of incompatible type 'uv_err_t' (aka 'struct uv_err_s')
fprintf(stderr, "File read error: %s: %s\n", uv_err_name(r), uv_strerror(r));
^
/usr/local/include/uv.h:426:44: note: passing argument to parameter 'err' here
UV_EXTERN const char* uv_err_name(uv_err_t err);
^
/Users/sang/workspace/github/http-server/server.c:182:56: error: use of undeclared identifier 'errno'
fprintf(stderr, "Allocate error: %s\n", strerror(errno));
^
/Users/sang/workspace/github/http-server/server.c:233:54: error: use of undeclared identifier 'errno'
fprintf(stderr, "Allocate error: %s\n", strerror(errno));
^
/Users/sang/workspace/github/http-server/server.c:239:57: error: passing 'int' to parameter of incompatible type 'uv_err_t' (aka 'struct uv_err_s')
fprintf(stderr, "Write error %s: %s\n", uv_err_name(r), uv_strerror(r));
^
/usr/local/include/uv.h:426:44: note: passing argument to parameter 'err' here
UV_EXTERN const char* uv_err_name(uv_err_t err);
^
/Users/sang/workspace/github/http-server/server.c:250:62: error: passing 'int' to parameter of incompatible type 'uv_err_t' (aka 'struct uv_err_s')
fprintf(stderr, "File read error: %s: %s\n", uv_err_name(result), uv_strerror(result));
^~~~~~
/usr/local/include/uv.h:426:44: note: passing argument to parameter 'err' here
UV_EXTERN const char* uv_err_name(uv_err_t err);
^
/Users/sang/workspace/github/http-server/server.c:276:57: error: passing 'int' to parameter of incompatible type 'uv_err_t' (aka 'struct uv_err_s')
fprintf(stderr, "Open error: %s: %s\n", uv_err_name(result), uv_strerror(result));
^~~~~~
/usr/local/include/uv.h:426:44: note: passing argument to parameter 'err' here
UV_EXTERN const char* uv_err_name(uv_err_t err);
^
/Users/sang/workspace/github/http-server/server.c:285:57: error: passing 'int' to parameter of incompatible type 'uv_err_t' (aka 'struct uv_err_s')
fprintf(stderr, "Stat error: %s: %s\n", uv_err_name(r), uv_strerror(r));
^
/usr/local/include/uv.h:426:44: note: passing argument to parameter 'err' here
UV_EXTERN const char* uv_err_name(uv_err_t err);
^
/Users/sang/workspace/github/http-server/server.c:342:7: warning: implicit declaration of function 'uv_try_write' is invalid in C99 [-Wimplicit-function-declaration]
r = uv_try_write((uv_stream_t_) request->handle, &buf, 1);
^
/Users/sang/workspace/github/http-server/server.c:380:54: error: use of undeclared identifier 'errno'
fprintf(stderr, "Allocate error: %s\n", strerror(errno));
^
/Users/sang/workspace/github/http-server/server.c:386:57: error: passing 'int' to parameter of incompatible type 'uv_err_t' (aka 'struct uv_err_s')
fprintf(stderr, "Open error: %s: %s\n", uv_err_name(r), uv_strerror(r));
^
/usr/local/include/uv.h:426:44: note: passing argument to parameter 'err' here
UV_EXTERN const char_ uv_err_name(uv_err_t err);
^
/Users/sang/workspace/github/http-server/server.c:399:60: error: passing 'int' to parameter of incompatible type 'uv_err_t' (aka 'struct uv_err_s')
fprintf(stderr, "Connect error: %s: %s\n", uv_err_name(status), uv_strerror(status));
^~~~~~
/usr/local/include/uv.h:426:44: note: passing argument to parameter 'err' here
UV_EXTERN const char* uv_err_name(uv_err_t err);
^
/Users/sang/workspace/github/http-server/server.c:405:54: error: use of undeclared identifier 'errno'
fprintf(stderr, "Allocate error: %s\n", strerror(errno));
^
/Users/sang/workspace/github/http-server/server.c:411:68: error: passing 'int' to parameter of incompatible type 'uv_err_t' (aka 'struct uv_err_s')
fprintf(stderr, "Socket creation error: %s: %s\n", uv_err_name(r), uv_strerror(r));
^
/usr/local/include/uv.h:426:44: note: passing argument to parameter 'err' here
UV_EXTERN const char* uv_err_name(uv_err_t err);
^
/Users/sang/workspace/github/http-server/server.c:417:59: error: passing 'int' to parameter of incompatible type 'uv_err_t' (aka 'struct uv_err_s')
fprintf(stderr, "Accept error: %s: %s\n", uv_err_name(r), uv_strerror(r));
^
/usr/local/include/uv.h:426:44: note: passing argument to parameter 'err' here
UV_EXTERN const char* uv_err_name(uv_err_t err);
^
/Users/sang/workspace/github/http-server/server.c:423:57: error: passing 'int' to parameter of incompatible type 'uv_err_t' (aka 'struct uv_err_s')
fprintf(stderr, "Flag error: %s: %s\n", uv_err_name(r), uv_strerror(r));
^
/usr/local/include/uv.h:426:44: note: passing argument to parameter 'err' here
UV_EXTERN const char* uv_err_name(uv_err_t err);
^
/Users/sang/workspace/github/http-server/server.c:427:29: warning: incompatible pointer types passing 'void (uv_handle_t , size_t, uv_buf_t *)' to parameter of type 'uv_alloc_cb'
(aka 'uv_buf_t (
)(uv_handle_t , size_t)') [-Wincompatible-pointer-types]
r = uv_read_start(stream, on_alloc, on_read);
^~~~~~~~
/usr/local/include/uv.h:593:55: note: passing argument to parameter 'alloc_cb' here
UV_EXTERN int uv_read_start(uv_stream_t
, uv_alloc_cb alloc_cb,
^
/Users/sang/workspace/github/http-server/server.c:427:39: warning: incompatible pointer types passing 'void (uv_stream_t , ssize_t, const uv_buf_t *)' to parameter of type
'uv_read_cb' (aka 'void (
)(uv_stream_t , ssize_t, uv_buf_t)') [-Wincompatible-pointer-types]
r = uv_read_start(stream, on_alloc, on_read);
^~~~~~~
/usr/local/include/uv.h:594:16: note: passing argument to parameter 'read_cb' here
uv_read_cb read_cb);
^
/Users/sang/workspace/github/http-server/server.c:429:57: error: passing 'int' to parameter of incompatible type 'uv_err_t' (aka 'struct uv_err_s')
fprintf(stderr, "Read error: %s: %s\n", uv_err_name(r), uv_strerror(r));
^
/usr/local/include/uv.h:426:44: note: passing argument to parameter 'err' here
UV_EXTERN const char
uv_err_name(uv_err_t err);
^
/Users/sang/workspace/github/http-server/server.c:497:33: error: too many arguments to function call, expected 2, have 3
r = uv_ip4_addr(ipaddr, port, &addr);
~~~~~~~~~~~ ^~~~~
/usr/local/include/uv.h:1794:1: note: 'uv_ip4_addr' declared here
UV_EXTERN struct sockaddr_in uv_ip4_addr(const char* ip, int port);
^
/usr/local/include/uv.h:43:20: note: expanded from macro 'UV_EXTERN'

define UV_EXTERN attribute((visibility("default")))

               ^

/Users/sang/workspace/github/http-server/server.c:499:60: error: passing 'int' to parameter of incompatible type 'uv_err_t' (aka 'struct uv_err_s')
fprintf(stderr, "Address error: %s: %s\n", uv_err_name(r), uv_strerror(r));
^
/usr/local/include/uv.h:426:44: note: passing argument to parameter 'err' here
UV_EXTERN const char* uv_err_name(uv_err_t err);
^
/Users/sang/workspace/github/http-server/server.c:508:68: error: passing 'int' to parameter of incompatible type 'uv_err_t' (aka 'struct uv_err_s')
fprintf(stderr, "Socket creation error: %s: %s\n", uv_err_name(r), uv_strerror(r));
^
/usr/local/include/uv.h:426:44: note: passing argument to parameter 'err' here
UV_EXTERN const char* uv_err_name(uv_err_t err);
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
3 warnings and 20 errors generated.
make[2]: *** [CMakeFiles/http-server.dir/server.c.o] Error 1
make[1]: *** [CMakeFiles/http-server.dir/all] Error 2
make: *** [all] Error 2
➜ build git:(master) ✗

could not build this project on wsl2:ubuntu20.04

cmake version: cmake version 3.16.3.

run mkdir build && cd build && cmake .. && make and hit an error:

[ 25%] Generating ../deps/libuv/.libs/libuv.a
/bin/sh: 1: Syntax error: word unexpected (expecting ")")
make[3]: *** [CMakeFiles/libuv.dir/build.make:61: ../deps/libuv/.libs/libuv.a] Error 2
make[2]: *** [CMakeFiles/Makefile2:77: CMakeFiles/libuv.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:111: CMakeFiles/http-server.dir/rule] Error 2
make: *** [Makefile:131: http-server] Error 2

I guess this asset (auto-generatedby cmake) cause this error:
cd /home/<username>/c/http-server/deps/libuv && sh -c [\ !\ -f\ .libs/libuv.a\ ]\ &&\ (./autogen.sh\ &&\ ./configure\ --enable-static\ --disable-shared\ &&\ make\ -k\ libuv.la)

try to update manually :sh -c "[ ! -f .libs/libuv.a ] && (./autogen.sh && ./configure --enable-static --disable-shared && make -k libuv.la)" and hit another error😵:

  CCLD     libuv.la
[ 25%] Built target libuv
[ 50%] Linking C executable http-server
/usr/bin/ld: ../deps/libuv/.libs/libuv.a(libuv_la-fs.o): in function `uv__mkostemp_initonce':
/home/<username>/c/http-server/deps/libuv/src/unix/fs.c:270: undefined reference to `dlsym'
/usr/bin/ld: /home/<username>/c/http-server/deps/libuv/src/unix/fs.c:276: undefined reference to `dlerror'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/http-server.dir/build.make:100: http-server] Error 1
make[2]: *** [CMakeFiles/Makefile2:104: CMakeFiles/http-server.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:111: CMakeFiles/http-server.dir/rule] Error 2
make: *** [Makefile:131: http-server] Error 2

here is a related issue: libuv/libuv#2579 but closed for stale.

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.