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

Implement httpbench #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ The spider `download.py`, dumps the response body as unicode to the files. The l
bookworm Spider to scrape locally hosted site
broadworm Broad crawl spider to scrape locally hosted sites
cssbench Micro-benchmark for extraction using css
httpbench Scrapy HTTP download handler test
itemloader Item loader benchmarker
linkextractor Micro-benchmark for LinkExtractor()
urlparseprofile Urlparse benchmarker
Expand Down
18 changes: 18 additions & 0 deletions bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,24 @@ def cssbench(obj):
obj.vmprof)


@cli.command()
@click.pass_obj
def httpbench(obj):
"""Scrapy HTTP download handler test"""
scrapy_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'execute.py')
settings = " ".join("-s '%s'" % s for s in obj.set)
arg = "%s runspider httpbench.py %s" % (scrapy_path, settings)

calculator(
"HTTP Benchmark",
arg,
obj.n_runs,
obj.only_result,
obj.upload_result,
obj.vmprof
)


@cli.command()
@click.pass_obj
def xpathbench(obj):
Expand Down
38 changes: 38 additions & 0 deletions httpbench.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from datetime import datetime

from scrapy import Request, Spider
from six import text_type


class HTTPSpider(Spider):
"""Spider equivalent to https://http1.golang.org/gophertiles

Use the DOWNLOAD_HANDLERS setting to set the download handler to test.
"""
name = 'httpbench'

def start_requests(self):
self.response_count = 0
self.start_time = datetime.utcnow()
version = (
'2' if '2' in self.settings.getwithbase('DOWNLOAD_HANDLERS')['https']
else '1'
)
for x in range(14):
for y in range(11):
yield Request(
'https://http{version}.golang.org/gophertiles?x={x}&y={y}&latency=0'
.format(
version=version,
x=x,
y=y,
)
)

def parse(self, response):
self.response_count += 1

def close(self, reason):
run_time = datetime.utcnow() - self.start_time
with open("Benchmark.txt", 'w') as f:
f.write(text_type(self.response_count / run_time.total_seconds()))