"Scrapy Reptile Series 2" performance tuning

Source: Internet
Author: User



Speed up the crawler:

In the settings.py TIMEOUT set small points to increase the number of concurrent (concurrent_requests) bottlenecks in Io, so it is possible to Io run full, but the CPU is not full, so you use the CPU to speed up the crawl is actually not tenable. It is better to open a few processes to run the cycle of death, so that the CPU is full of setting.py inside, you can put single IP or single domain concurrent number of threads to 16 or higher, I found that two days 16 threads on the general site is not a problem, and scrapy Your own scheduling and retry system can ensure that each page is successfully crawled.   As for the distributed, the premise or the capture of the server can be accepted, under this premise, I have a relatively stupid method:  assume that the number of pages is known, and the URL of the main page is regular, for example, a lot of WordPress is domain.com/page/ 2000 such, the same project open 100 processes, each process starturl is PAGE/1, PAGE/21,PAGE/41, and then realize a stopurl, so that the 100 processes equally divided 2000 pages. On the one hand the speed is fast (assuming there is no physical bottleneck), on the other hand these 100 processes are independent of each other, even if which process hangs, the risk of the re-running is apportioned. Dynamic page is best to find AJAX transmission of JSON data, and then crawl the content needed for directional acquisition can be replaced by the XPath fast proxy or unstable, if the use of the amount of telecommunications network, you can try routing Replay update IP fast link extractor. Python's sgmlparser is too slow, using Sgmllinkextractor will allow the crawler to waste most of their time parsing the Web page, preferably by writing a link extractor (we've written one based on lxml, or we can use a library like soup. )。 You can also use regular expressions to write link extractor, fast, the problem is not understand HTML semantics, will include the link in the note. Also based on JavaScript redirection URLs are extracted here. By default, you can see that the scrapy has 10 threads. However, for general operations such as download and parse, they are single-threaded-all within the same thread. Consider gevent, a network IO-intensive type for reptiles. The efficiency will be very high first to try Urllib and urllib2, familiar with the basic reptilian thinking. And then get acquainted, and then look at R.Equests, this is also the URLLIB\URLLIB2 package, familiar with the GRASP and analysis of page components, to understand post, get are what the principle and practical scrapy asynchronous (done several projects, very useful) distributed (not yet involved), Redis,scrapyd




Reference: "Scrapy grasping speed Problem" https://www.v2ex.com/t/232070 "several methods of running multiple scrapy reptiles at the same time" http://www.cnblogs.com/rwxwsblog/p/4578764.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.