version 0.2.0
This commit is contained in:
parent
d19c4efad3
commit
3dddee43f7
32 changed files with 243 additions and 1020337 deletions
2
benchmarks/http_1_v_11/anthracite.Dockerfile
Normal file
2
benchmarks/http_1_v_11/anthracite.Dockerfile
Normal file
|
@ -0,0 +1,2 @@
|
|||
FROM anthracite:latest
|
||||
COPY ./www/ /www/
|
36
benchmarks/http_1_v_11/benchmark.py
Normal file
36
benchmarks/http_1_v_11/benchmark.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
import socket
|
||||
import time
|
||||
|
||||
num_requests = 10000
|
||||
|
||||
http_1_times = []
|
||||
http_11_times = []
|
||||
|
||||
print('=====[ Anthracite Benchmarking Tool ]=====')
|
||||
print(f'Requests : {num_requests}')
|
||||
print(f'Test : HTTP 1.0 vs HTTP 1.1\n\n')
|
||||
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
s.connect(("localhost" , 8091))
|
||||
for i in range(num_requests):
|
||||
start_time = time.time()
|
||||
s.sendall(b"GET /test.html HTTP/1.1\r\nAccept: text/html\r\nConnection: keep-alive\r\n\r\n")
|
||||
data = s.recv(220)
|
||||
end_time = time.time()
|
||||
http_11_times.append((end_time - start_time))
|
||||
s.close()
|
||||
|
||||
for i in range(num_requests):
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
start_time = time.time()
|
||||
s.connect(("localhost" , 8091))
|
||||
s.sendall(b"GET /test.html HTTP/1.0\r\nAccept: text/html\r\n\r\n")
|
||||
data = s.recv(220)
|
||||
end_time = time.time()
|
||||
http_1_times.append((end_time - start_time))
|
||||
s.close()
|
||||
|
||||
run_time_1 = sum(http_1_times)
|
||||
run_time_11 = sum(http_11_times)
|
||||
print(f'HTTP/1.0 Total Time: {run_time_1:.4f} seconds')
|
||||
print(f'HTTP/1.1 Total Time: {run_time_11:.4f} seconds')
|
7
benchmarks/http_1_v_11/docker-compose.yaml
Normal file
7
benchmarks/http_1_v_11/docker-compose.yaml
Normal file
|
@ -0,0 +1,7 @@
|
|||
services:
|
||||
anthracite:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: anthracite.Dockerfile
|
||||
ports:
|
||||
- "8091:80"
|
4
benchmarks/http_1_v_11/rebuild-container.sh
Executable file
4
benchmarks/http_1_v_11/rebuild-container.sh
Executable file
|
@ -0,0 +1,4 @@
|
|||
cd ../..
|
||||
docker build . -t anthracite:latest
|
||||
cd benchmarks/http_1_v_11
|
||||
docker compose build
|
1
benchmarks/http_1_v_11/run.sh
Executable file
1
benchmarks/http_1_v_11/run.sh
Executable file
|
@ -0,0 +1 @@
|
|||
docker-compose stop && ./rebuild-container.sh && docker compose up -d && clear && python3 benchmark.py && docker-compose stop
|
2
benchmarks/http_1_v_11/www/test.html
Normal file
2
benchmarks/http_1_v_11/www/test.html
Normal file
|
@ -0,0 +1,2 @@
|
|||
<h1>Anthracite Benchmarking</h1>
|
||||
<p>Test document to test the speed of HTTP/1.0 and HTTP/1.1</p>
|
2
benchmarks/load_test/anthracite.Dockerfile
Normal file
2
benchmarks/load_test/anthracite.Dockerfile
Normal file
|
@ -0,0 +1,2 @@
|
|||
FROM anthracite:latest
|
||||
COPY ./www/ /www/
|
3
benchmarks/load_test/apache.Dockerfile
Executable file
3
benchmarks/load_test/apache.Dockerfile
Executable file
|
@ -0,0 +1,3 @@
|
|||
FROM httpd:2.4
|
||||
WORKDIR /usr/local/apache2/htdocs/
|
||||
COPY ./www/ .
|
71
benchmarks/load_test/benchmark.py
Normal file
71
benchmarks/load_test/benchmark.py
Normal file
|
@ -0,0 +1,71 @@
|
|||
import requests
|
||||
import time
|
||||
import math
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from http.client import HTTPConnection
|
||||
|
||||
HTTPConnection._http_vsn_str = 'HTTP/1.0'
|
||||
urls = { 'anthracite': 'http://localhost:8081/50MB.zip','nginx': 'http://localhost:8082/50MB.zip', 'apache': 'http://localhost:8083/50MB.zip' }
|
||||
num_requests = 1000
|
||||
num_users = 100 # number of threads
|
||||
response_times = {}
|
||||
|
||||
def percentile(N, percent, key=lambda x:x):
|
||||
if not N:
|
||||
return None
|
||||
N.sort()
|
||||
k = (len(N)-1) * percent
|
||||
f = math.floor(k)
|
||||
c = math.ceil(k)
|
||||
if f == c:
|
||||
return key(N[int(k)])
|
||||
d0 = key(N[int(f)]) * (c-k)
|
||||
d1 = key(N[int(c)]) * (k-f)
|
||||
return d0+d1
|
||||
|
||||
# Define a function to make an HTTP request and measure the response time
|
||||
def make_request(request_number, server_name):
|
||||
start_time = time.time()
|
||||
response = requests.get(urls[server_name])
|
||||
end_time = time.time()
|
||||
|
||||
if response.status_code == 200:
|
||||
response_time = end_time - start_time
|
||||
response_times[server_name].append(response_time)
|
||||
else:
|
||||
print(f'Request {request_number}: Request failed with status code {response.status_code}')
|
||||
|
||||
print('=====[ Anthracite Benchmarking Tool ]=====')
|
||||
print(f'Requests : {num_requests}')
|
||||
print(f'Users/Threads: {num_users}')
|
||||
print(f'Test : Load Test\n\n')
|
||||
start_all_time = time.time()
|
||||
|
||||
futures = []
|
||||
|
||||
for server_name in urls:
|
||||
response_times[server_name] = []
|
||||
with ThreadPoolExecutor(max_workers=num_users) as executor:
|
||||
futures += [executor.submit(make_request, i + 1, server_name) for i in range(num_requests)]
|
||||
|
||||
# Wait for all requests to complete
|
||||
for future in futures:
|
||||
future.result()
|
||||
|
||||
end_all_time = time.time()
|
||||
|
||||
for server_name in urls:
|
||||
print(f'====[ {server_name} ]=====')
|
||||
average_response_time = sum(response_times[server_name]) / len(response_times[server_name])
|
||||
total_response_time = sum(response_times[server_name])
|
||||
print(f'Average Response Time: {average_response_time:.4f} seconds')
|
||||
print(f'p995 Response Time : {percentile(response_times[server_name], .995):.4f} seconds')
|
||||
print(f'p99 Response Time : {percentile(response_times[server_name], .99):.4f} seconds')
|
||||
print(f'p90 Response Time : {percentile(response_times[server_name], .90):.4f} seconds')
|
||||
print(f'p75 Response Time : {percentile(response_times[server_name], .75):.4f} seconds')
|
||||
print(f'p50 Response Time : {percentile(response_times[server_name], .50):.4f} seconds')
|
||||
print(f'Total Response Time : {total_response_time:.4f} seconds')
|
||||
|
||||
total_test_time = end_all_time - start_all_time
|
||||
print('==========')
|
||||
print(f'Total Test Time : {total_test_time:.4f} seconds')
|
19
benchmarks/load_test/docker-compose.yaml
Normal file
19
benchmarks/load_test/docker-compose.yaml
Normal file
|
@ -0,0 +1,19 @@
|
|||
services:
|
||||
anthracite:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: anthracite.Dockerfile
|
||||
ports:
|
||||
- "8081:80"
|
||||
nginx:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: nginx.Dockerfile
|
||||
ports:
|
||||
- "8082:80"
|
||||
apache:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: apache.Dockerfile
|
||||
ports:
|
||||
- "8083:80"
|
2
benchmarks/load_test/nginx.Dockerfile
Normal file
2
benchmarks/load_test/nginx.Dockerfile
Normal file
|
@ -0,0 +1,2 @@
|
|||
FROM nginx:alpine
|
||||
COPY ./www/ /usr/share/nginx/html
|
5
benchmarks/load_test/rebuild-container.sh
Executable file
5
benchmarks/load_test/rebuild-container.sh
Executable file
|
@ -0,0 +1,5 @@
|
|||
cd ../..
|
||||
docker build . -t anthracite:latest
|
||||
cd benchmarks/load_test
|
||||
docker compose build
|
||||
docker compose up -d
|
1
benchmarks/load_test/run.sh
Executable file
1
benchmarks/load_test/run.sh
Executable file
|
@ -0,0 +1 @@
|
|||
docker-compose stop && ./rebuild-container.sh && docker compose up -d && clear && python3 benchmark.py && docker-compose stop
|
BIN
benchmarks/load_test/www/50MB.zip
Normal file
BIN
benchmarks/load_test/www/50MB.zip
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue