performance improvements + a good amount of changes

This commit is contained in:
Nicholas Orlowsky 2023-10-16 14:36:17 -04:00
parent 89a6d9a528
commit 0649a28a28
No known key found for this signature in database
GPG key ID: BE7DF0188A405E2B
24 changed files with 2040744 additions and 70 deletions

View file

@ -0,0 +1,2 @@
FROM anthracite:latest
COPY ./www/ /www/

3
benchmark/apache.Dockerfile Executable file
View file

@ -0,0 +1,3 @@
FROM httpd:2.4
WORKDIR /usr/local/apache2/htdocs/
COPY ./www/ .

69
benchmark/benchmark.py Normal file
View file

@ -0,0 +1,69 @@
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/large.html','nginx': 'http://localhost:8082/large.html', 'apache': 'http://localhost:8083/large.html' }
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}\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')

View 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"

View file

@ -0,0 +1,2 @@
FROM nginx:alpine
COPY ./www/ /usr/share/nginx/html

5
benchmark/rebuild-container.sh Executable file
View file

@ -0,0 +1,5 @@
cd ..
docker build . -t anthracite:latest
cd benchmark
docker build . -t benchmark-anthracite -f anthracite.Dockerfile
docker compose up -d

1020251
benchmark/www/large.html Normal file

File diff suppressed because it is too large Load diff