Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upUsage of HttpCompressionMiddleware needs to be relfected in Scrapy stats #4797
Labels
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summary
Usage of
HttpCompressionMiddlewareneeds to be relfected in Scrapy stats.Motivation
In order to estimate scrapy memory usage efficiency and prevent.. memory leaks like this.
I will need to know:
trackref)A lot of websites use compression to reduce traffic. In this case I would like to calculate average size of decompressed responses to estimate p.2.
Decompression process means that at some point application will require to allocate memory to store both compressed and decompressed response body and I will need to know this sizes to have more complete vision of scrapy memory usage.
Also size of decompressed body will be several times more than size of compressed response and it will affect scrapy memory usage.
Describe alternatives you've considered
The easiest one - is to change priority of
DownloaderStatsmiddleware and check difference indownloader/response_bytesstats parameter.Stats from quotes.toscrape.com spider (it uses
gzipcompression) with default settings:And with changed priority of
DownloaderStatsmiddleware:Average size of compressed response (by default) - 2453 bytes.
Average size of decompressed response - 11019 bytes (~4.5 times more).
Additional context
Potential solution is to add something like this:
self.stats.inc_value('decompressed_bytes', spider=spider)into
process_responsemethod ofHttpCompressionMiddleware