thsheep / scrapy_redis_cluster

scrapy-redis的集群版,可以借助Redis集群实现海量网站的独立去重,避免单机内存不足的尴尬
138 stars 41 forks source link

scrapy-redis-cluster如果redis集群有密码,该如何配置? #4

Closed chbsxni closed 5 years ago

chbsxni commented 5 years ago

scrapy-redis-cluster如果redis集群有密码,该如何配置?

chbsxni commented 5 years ago

你好,密码问题已经解决了. 但是,现在出现另外一个问题。

我重写了make_requests_from_url方法,push了很多很多的start_url,url中有中文。 使用scrapy-redis-cluster的时候,会报一个错误:

builtins.UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

原谅我不会截图。出现的错误行:

File "/Users/xxx/.virtualenvs/spider_py3.6/lib/python3.6/site-packages/rediscluster/client.py", line 371, in execute_command return self.parse_response(r, command, **kwargs) File "/Users/xxx/.virtualenvs/spider_py3.6/lib/python3.6/site-packages/redis/client.py", line 680, in parse_response response = connection.read_response() File "/Users/xxx/.virtualenvs/spider_py3.6/lib/python3.6/site-packages/redis/connection.py", line 624, in read_response response = self._parser.read_response() File "/Users/xxx/.virtualenvs/spider_py3.6/lib/python3.6/site-packages/redis/connection.py", line 326, in read_response response = self.encoder.decode(response) File "/Users/xxx/.virtualenvs/spider_py3.6/lib/python3.6/site-packages/redis/connection.py", line 125, in decode value = value.decode(self.encoding, self.encoding_errors)

还望大神指点迷津

thsheep commented 5 years ago

REDIS_ENCODING = 'UTF-8' 试试

chbsxni commented 5 years ago

兄弟,别闹…需要验证…,配置encoding能有用么…

对了,rediscluster的反应时间,比单节点redis慢5-8倍左右,是否正常?有没有优化方案?除了用redis pipelin

---原始邮件--- 发件人: "哎哟卧槽"notifications@github.com 发送时间: 2019年6月21日(星期五) 下午4:54 收件人: "thsheep/scrapy_redis_cluster"scrapy_redis_cluster@noreply.github.com; 抄送: "chbsxni"chbsxni@qq.com;"Author"author@noreply.github.com; 主题: Re: [thsheep/scrapy_redis_cluster] scrapy-redis-cluster如果redis集群有密码,该如何配置? (#4)

REDIS_ENCODING = 'UTF-8' 试试

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

thsheep commented 5 years ago

我说的是 你第二个URL有中文的编码问题。

速度 相对于单节点慢,似乎是因为Redis 在集群模式下,涉及到一个 Ask 和 Move 的操作。

简单来讲就是,你存储的 Key 根据 CRC16 算法;被分布到了集群当中。

客户端并不知道这个 Key 被分配到了哪一个节点上,需要向集群中任一一台发起请求。节点拿到后会检查 Key 是否分配给了自己。是就正常返回数据。否则 就向客户端返回 ASK 或者 Move 指令,并告诉客户端应该去哪一个节点 获取 Key。

简单点如下图:

image

所以造成了速度要比单节点慢。

优化方法很简单,缓存 Key 与 Node 的对应关系。这样就可以直接去访问对应节点。

省掉了 ASK 和 Move 的耗时