Created
December 29, 2018 07:10
-
-
Save monsterxx03/a33fbc20dc535d29c3d5802cac46538c to your computer and use it in GitHub Desktop.
nagle's algorithm test
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
import socket | |
import time | |
host = '127.0.0.1' | |
port = 80 | |
TOTAL_TIME = 0 | |
count = 10 | |
def test_func(s, together=False): | |
global TOTAL_TIME | |
header = b'POST / HTTP/1.1\r\nHost: 127.0.0.1\r\nConnection: keep-alive\r\nUser-Agent: curl/7.58.0\r\nContent-Length: 3\r\nContent-Type: application/x-www-form-urlencoded\r\nAccept: */*\r\n\r\n' | |
body = b'abc' | |
_all = header + body | |
for i in range(count): | |
start = time.time() | |
if together: | |
s.send(_all) | |
else: | |
s.send(header) | |
s.send(body) | |
s.recv(1024) | |
TOTAL_TIME += time.time() - start | |
print(TOTAL_TIME * 1000) | |
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | |
s.connect((host, port)) | |
#s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) | |
test_func(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment