推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
daiqiangbudainiu
V2EX  ›  Python

请教 Linux 下 Scrapy 内存占用非常大的问题

  •  
  •   daiqiangbudainiu · Jan 24, 2019 · 2309 views
    This topic created in 2811 days ago, the information mentioned may be changed or developed.
    我是爬取一个视频网站,爬取到地址放到 file piplines 中去下载

    在 Mac 上占用内存很小,只有 100M 多

    放到了阿里云上,内存占用非常大,有 700M 多

    请教这是怎么回事
    Supplement 1  ·  Jan 24, 2019

    parse 的代码

        def parse_video_page(self, response: HtmlResponse):
            self.log('开始分析视频真实地址', level=logging.WARNING)
            title = response.css('#viewvideo-title::text').extract_first().strip()
            video_link = response.css('source::attr(src)').extract_first()
            if video_link:
                # 处理一下链接中 http://185.38.13.130//mp43/2998... 这种的 url
                video_link_list = video_link.split('//')
                real_video_link = video_link_list[0] + '//' + video_link_list[1] + '/' + video_link_list[2]
    
                self.log('获取到下载链接,丢入下载 pipelines', level=logging.WARNING)
                yield New91CrawlerItem(file_urls=real_video_link, file_name=title)
            else:
                self.log('获取视频下载地址失败,地址:{0}'.format(response.url), level=logging.WARNING)
    

    这是 pipelines 的代码

    class New91CrawlerPipeline(FilesPipeline):
        def get_media_requests(self, item, info):
            return scrapy.Request(url=item['file_urls'], meta=item)
    
        def file_path(self, request, response=None, info=None):
            name = request.meta['file_name']
            return name + '.mp4'
    
    Supplement 2  ·  Jan 25, 2019
    新手,求教
    4 replies  •  2019-01-24 02:35:00 +08:00
    wind3110991
        1
    wind3110991  
       Jan 24, 2019 via iPhone
    贴代码,还有两个环境部署的文件配置,阿里云什么系统什么配置
    daiqiangbudainiu
        2
    daiqiangbudainiu  
    OP
       Jan 24, 2019
    @wind3110991 配置用的默认的,阿里云就是最低配的那个 1 核 1G 内存 Ubuntu 18 的系统
    daiqiangbudainiu
        3
    daiqiangbudainiu  
    OP
       Jan 24, 2019
    @wind3110991 我自己分析发现,减少并发数量可以降低内存,推测是由于服务器网速快,所以默认的 16 个线程都能满速下载,然后下载的时候,scrapy 用的 requests 应该设置的 chunked 比较大
    daiqiangbudainiu
        4
    daiqiangbudainiu  
    OP
       Jan 24, 2019
    @wind3110991

    我这个推测应该不准,我修改了配置文件,改成了 ip 域名,都是 3 个线程,依然内存会爆
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2255 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 04:50 · PVG 12:50 · LAX 21:50 · JFK 00:50
    ♥ Do have faith in what you're doing.