Skip to content
This repository

TinyHttpServer in Python

branch: master
README
An easy http server programmed in Python

Installation Guide:
Download the code, and uncompress it. 

Execute the command in your terminal: 
    python http.py

Open your web browser, and type in:http://localhost:11111/index.html, Done! 

Features:
1. Simple GET
2. File Cache(Deprecated, as it need to use the /dev/shm/ memory file)
3. Epoll(using Edge Trigger)
4. Http1.1 pipeline
5. Gzip
6. Virtual Host
7. Add multiprocessing, which could overcome the C10k problem(3 worker processes could nearly handle 3 times requests)
8. Replace File Cache with Dict Cache


Apache Bench Test(Single Process)
ab -n 100000 -c 100 http://example.com:11111/index.html
Server Software:        PyTinyHttpServer
Server Hostname:        example.com
Server Port:            11111

Document Path:          /index.html
Document Length:        137 bytes

Concurrency Level:      100
Time taken for tests:   17.354 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      29300000 bytes
HTML transferred:       13700000 bytes
Requests per second:    5762.35 [#/sec] (mean)
Time per request:       17.354 [ms] (mean)
Time per request:       0.174 [ms] (mean, across all concurrent requests)
Transfer rate:          1648.80 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       7
Processing:     7   17   1.9     18      34
Waiting:        7   17   1.9     18      34
Total:          9   17   1.9     18      36

Percentage of the requests served within a certain time (ms)
  50%     18
  66%     18
  75%     18
  80%     18
  90%     18
  95%     19
  98%     23
  99%     25
 100%     36 (longest request)


###########################################################################
Apache Bench Test(With multiprocessing support, default 3 worker processes)
ab -n 100000 -c 100 http://example.com:11111/index.html
Server Software:        PyTinyHttpServer
Server Hostname:        example.com
Server Port:            11111

Document Path:          /index.html
Document Length:        137 bytes

Concurrency Level:      100
Time taken for tests:   8.338 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      29300000 bytes
HTML transferred:       13700000 bytes
Requests per second:    11993.81 [#/sec] (mean)
Time per request:       8.338 [ms] (mean)
Time per request:       0.083 [ms] (mean, across all concurrent requests)
Transfer rate:          3431.82 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       9
Processing:     0    8   3.4      8      33
Waiting:        0    8   3.4      8      33
Total:          0    8   3.4      8      33

Percentage of the requests served within a certain time (ms)
  50%      8
  66%      9
  75%     10
  80%     11
  90%     13
  95%     14
  98%     16
  99%     17
 100%     33 (longest request)


ab -n 500000 -c 300 http://localhost:11111/index.html
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 50000 requests
Completed 100000 requests
Completed 150000 requests
Completed 200000 requests
Completed 250000 requests
Completed 300000 requests
Completed 350000 requests
Completed 400000 requests
Completed 450000 requests
Completed 500000 requests
Finished 500000 requests


Server Software:        PyTinyHttpServer
Server Hostname:        localhost
Server Port:            11111

Document Path:          /index.html
Document Length:        137 bytes

Concurrency Level:      300
Time taken for tests:   33.776 seconds
Complete requests:      500000
Failed requests:        0
Write errors:           0
Total transferred:      146500000 bytes
HTML transferred:       68500000 bytes
Requests per second:    14803.52 [#/sec] (mean)
Time per request:       20.265 [ms] (mean)
Time per request:       0.068 [ms] (mean, across all concurrent requests)
Transfer rate:          4235.77 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    4  88.1      1    3014
Processing:     1   16   6.0     16     245
Waiting:        1   16   6.1     15     244
Total:          1   20  88.3     17    3034

Percentage of the requests served within a certain time (ms)
  50%     17
  66%     19
  75%     21
  80%     22
  90%     25
  95%     28
  98%     31
  99%     34
 100%   3034 (longest request)

Something went wrong with that request. Please try again.