From 193f170df97d7bbcc5edc50913e1be3beffbb542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Chaves?= Date: Wed, 19 Mar 2025 19:31:02 +0100 Subject: [PATCH] Minor refactoring --- docs/topics/optimize.rst | 63 ++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/docs/topics/optimize.rst b/docs/topics/optimize.rst index 3dd7282f0..3aa2b688b 100644 --- a/docs/topics/optimize.rst +++ b/docs/topics/optimize.rst @@ -1,8 +1,8 @@ .. _optimize: -============= -Optimizations -============= +============ +Optimization +============ Scrapy offers different ways to speed up crawls for specific :ref:`use cases ` and to :ref:`lower resource usage `. @@ -73,42 +73,25 @@ For broad crawls, consider these adjustments: Lowering resource usage ======================= -General tips ------------- - -- Try :ref:`using the asyncio reactor `, installing - :doc:`uvloop ` and setting :setting:`ASYNCIO_EVENT_LOOP` to - :class:`uvloop.Loop`. - - Alternatively, try switching :setting:`TWISTED_REACTOR` to :doc:`some other - reactor `. - -- Disable unused :ref:`components `. - - For example, set :setting:`COOKIES_ENABLED` to ``False`` unless you need - cookies. - - -Lowering CPU usage ------------------- - -- Set :setting:`LOG_LEVEL` to ``"INFO"`` or higher. - - Lowering memory usage --------------------- -- If lowering your crawl speed is OK: +- Lower :setting:`SCRAPER_SLOT_MAX_ACTIVE_SIZE`. + +- Lower the number of :ref:`scheduled requests ` held in + memory: - Increase the :attr:`~scrapy.Request.priority` of requests whose - :attr:`~scrapy.Request.callback` cannot yield additional requests. + :attr:`~scrapy.Request.callback` cannot yield additional + requests. - If you have many seed requests (see - :meth:`~scrapy.Spider.yield_seeds`), set :setting:`SEEDING_POLICY` to + :meth:`~scrapy.Spider.yield_seeds`), set + :setting:`SEEDING_POLICY` to :class:`~scrapy.SeedingPolicy.lazy` or :class:`~scrapy.SeedingPolicy.idle`. - - Lower :setting:`SCRAPER_SLOT_MAX_ACTIVE_SIZE`. + - Set :setting:`JOBDIR` to offload all scheduled requests to disk. - Be in the lookout for :ref:`memory leaks `. @@ -123,3 +106,25 @@ Lowering network usage .. _brotli: https://pypi.org/project/Brotli/ .. _zstd-compressed: https://www.ietf.org/rfc/rfc8478.txt .. _zstandard: https://pypi.org/project/zstandard/ + + +Lowering CPU usage +------------------ + +- Set :setting:`LOG_LEVEL` to ``"INFO"`` or higher. + + +Other tips +---------- + +- Try :ref:`using the asyncio reactor `, installing + :doc:`uvloop ` and setting :setting:`ASYNCIO_EVENT_LOOP` to + :class:`uvloop.Loop`. + + Alternatively, try switching :setting:`TWISTED_REACTOR` to :doc:`some other + reactor `. + +- Disable unused :ref:`components `. + + For example, set :setting:`COOKIES_ENABLED` to ``False`` unless you need + cookies.