Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pip upgrade for windows which seems to be failing on travis #136

Merged
merged 2 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ matrix:
osx_image: xcode11
language: shell
python: 3.7
- name: "Python 3.7 on Windows"
os: windows
language: shell
before_install:
- choco install python
- python -m pip install --upgrade pip
env:
- PATH=/c/Python37:/c/Python37/Scripts:$PATH
- TESTING_ON_TRAVIS=1
install:
- pip3 install -r requirements-testing.txt
script: python3 -m coverage run --source=proxy tests.py || python -m coverage run --source=proxy tests.py
Expand Down
69 changes: 50 additions & 19 deletions benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import argparse
import asyncio
import sys
import time
from typing import List, Tuple

import proxy
Expand Down Expand Up @@ -48,17 +49,36 @@ async def open_connections(self) -> None:
self.clients.append(await asyncio.open_connection('::', 8899))
print('Opened ' + str(self.n) + ' connections')

def send_requests(self) -> None:
for _, writer in self.clients:
writer.write(proxy.build_http_request(
proxy.httpMethods.GET, b'/'
))
@staticmethod
async def send(writer: asyncio.StreamWriter) -> None:
try:
while True:
writer.write(proxy.build_http_request(
proxy.httpMethods.GET, b'/'
))
# await asyncio.sleep(0.1)
except KeyboardInterrupt:
pass

@staticmethod
async def recv(idd: int, reader: asyncio.StreamReader) -> None:
last_status_time = time.time()
num_completed_requests_per_connection: int = 0
try:
while True:
response = proxy.HttpParser(proxy.httpParserTypes.RESPONSE_PARSER)
while response.state != proxy.httpParserStates.COMPLETE:
raw = await reader.read(proxy.DEFAULT_BUFFER_SIZE)
print(raw)
response.parse(raw)

async def recv_responses(self) -> None:
for reader, _ in self.clients:
response = proxy.HttpParser(proxy.httpParserTypes.RESPONSE_PARSER)
while response.state != proxy.httpParserStates.COMPLETE:
response.parse(await reader.read(proxy.DEFAULT_BUFFER_SIZE))
num_completed_requests_per_connection += 1
if num_completed_requests_per_connection % 50 == 0:
now = time.time()
print('[%d] Made 50 requests in last %.2f seconds' % (idd, now - last_status_time))
last_status_time = now
except KeyboardInterrupt:
pass

async def close_connections(self) -> None:
for reader, writer in self.clients:
Expand All @@ -67,19 +87,30 @@ async def close_connections(self) -> None:
print('Closed ' + str(self.n) + ' connections')

async def run(self) -> None:
num_completed_requests_per_connection: int = 0
try:
await self.open_connections()
print('Exchanging request / response packets')
while True:
self.send_requests()
await self.recv_responses()
num_completed_requests_per_connection += 1
await asyncio.sleep(0.1)
readers = []
writers = []
idd = 0
for reader, writer in self.clients:
readers.append(
asyncio.create_task(
self.recv(idd, reader)
)
)
writers.append(
asyncio.create_task(
self.send(writer)
)
)
idd += 1
await asyncio.gather(*(readers + writers))
finally:
await self.close_connections()
print('Exchanged ' + str(num_completed_requests_per_connection) +
' request / response per connection')
try:
await self.close_connections()
except RuntimeError:
pass


def main(input_args: List[str]) -> None:
Expand Down