Last active
December 13, 2023 13:50
-
-
Save tolgahanakgun/4f449368e3a62224c9a3c1af7a084521 to your computer and use it in GitHub Desktop.
Send 10GB random data via http requests to test the network throughput
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# -*- coding: utf-8 -*- | |
# | |
# curl -o /dev/null http://SERVER_IP:SERVER_PORT | |
# time printf 'GET / HTTP/1.1\n\n' | netcat SERVER_IP SERVER_PORT > /dev/null | |
import os | |
import argparse | |
from ipaddress import ip_address | |
from http.server import HTTPServer, BaseHTTPRequestHandler | |
EIGHT_MB_RAND = os.urandom(8 * 2**20) | |
CONTENT_LEN = 8 * 2**20 * 1280 | |
class MyHandler(BaseHTTPRequestHandler): | |
def do_GET(self): | |
self.send_response(200) | |
self.send_header("Content-type", "application/octet-stream") | |
self.send_header('Content-Disposition', 'inline; filename="10GB.bin"') | |
self.send_header("Content-Length", CONTENT_LEN) | |
self.end_headers() | |
for x in range(1280): | |
self.wfile.write(EIGHT_MB_RAND) | |
def main() -> None: | |
parser = argparse.ArgumentParser(description="Send 10GB rand data over http for speed test") | |
parser.add_argument("-b", "--bind", default="127.0.0.1", type=ip_address, | |
help="Bind server to this IP") | |
parser.add_argument("-p", "--port", default=8091, type=int, | |
help="Bind server to this port") | |
args = parser.parse_args() | |
print(f"Serving on {args.bind} port {args.port} ...") | |
server = HTTPServer((str(args.bind), args.port), MyHandler) | |
server.serve_forever() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment