Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 32 additions & 0 deletions httpbench.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from datetime import datetime

from scrapy import Request, Spider


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(
f'https://http{version}.golang.org/gophertiles?x={x}&y={y}&latency=0'
)

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(f"{self.response_count / run_time.total_seconds()}")