msgpack errors when using iter() with intervals between each batch call
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với scrapinghub/client/proxy.py, đặc biệt là iter, và scrapinghub/hubstorage/serialization.py, đặc biệt là mpdecode. Tái hiện các lỗi đã báo cáo với kích thước chunk là 25000 và 50000, sau đó so sánh chúng với kích thước đang hoạt động là 1000. Hoàn tất khi việc lặp vẫn đáng tin cậy trong quá trình xử lý các chunk lớn hơn mà không gặp UnicodeDecodeError đã báo cáo hoặc lỗi unhashable-dict.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Good Day!
I've encountered this peculiar issue when trying to save up memory by processing the items in chunks. Here's a strip down version of the code for reproduction of the issue:
import pandas as pd
from scrapinghub import ScrapinghubClient
def read_job_items_by_chunk(jobkey, chunk=10000):
"""In order to prevent OOM issues, the jobs' data must be read in
chunks.
This will return a generator of pandas DataFrames.
"""
client = ScrapinghubClient("APIKEY123")
item_generator = client.get_job(jobkey).items.iter()
while item_generator:
yield pd.DataFrame(
[next(item_generator) for _ in range(chunk)]
)
for df_chunk in read_job_items_by_chunk('123/123/123'):
# having a small chunk-size like 10000 won't have any problems
for df_chunk in read_job_items_by_chunk('123/123/123', chunk=25000):
# having a bug chunk-size like 25000 will throw out errors like the one below
Here's the common error it throws:
<omitted stack trace above>
[next(item_generator) for _ in range(chunk)]
File "/usr/local/lib/python2.7/site-packages/scrapinghub/client/proxy.py", line 115, in iter
_path, requests_params, **apiparams
File "/usr/local/lib/python2.7/site-packages/scrapinghub/hubstorage/serialization.py", line 33, in mpdecode
for obj in unpacker:
File "msgpack/_unpacker.pyx", line 459, in msgpack._unpacker.Unpacker.__next__ (msgpack/_unpacker.cpp:459)
File "msgpack/_unpacker.pyx", line 390, in msgpack._unpacker.Unpacker._unpack (msgpack/_unpacker.cpp:390)
File "/usr/local/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position 67: invalid start byte
Moreover, it throws out a different error when using a much bigger chunk-size, like 50000:
<omitted stack trace above>
[next(item_generator) for _ in range(chunk)]
File "/usr/local/lib/python2.7/site-packages/scrapinghub/client/proxy.py", line 115, in iter
_path, requests_params, **apiparams
File "/usr/local/lib/python2.7/site-packages/scrapinghub/hubstorage/serialization.py", line 33, in mpdecode
for obj in unpacker:
File "msgpack/_unpacker.pyx", line 459, in msgpack._unpacker.Unpacker.__next__ (msgpack/_unpacker.cpp:459)
File "msgpack/_unpacker.pyx", line 390, in msgpack._unpacker.Unpacker._unpack (msgpack/_unpacker.cpp:390)
TypeError: unhashable type: 'dict'
I find that the workaround/solution for this would be to have a lower value for chunk. So far, 1000 works great.
This uses scrapy:1.5 stack in Scrapy Cloud.
I'm guessing this might have something to do with the long waiting time that happens when processing the pandas DataFrame chunk, and when the next batch of items are being iterated, the server might have deallocated the pointer to it or something.
May I ask if there might be a solution for this? since a much bigger chunk size will help with the speed of our jobs.
I've marked it as bug for now as this is quite an unexpected/undocumented behavior.
Cheers!
- Ngôn ngữ chính
- Python
- Star
- 204
- Fork
- 62
- Merge trung bình
- 6 phút
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của scrapinghub/python-scrapinghub
-
Incorrect information for Samples in Job documentationCó thể đã có người làm @AdrianAtZyte đã nhận 66 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
-
Zyte Job API: Provision to support Cron Expression or Time IntervalCó thể đã có người làm @AdrianAtZyte đã nhận 67 ngày trước. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
-
Add async supportCó thể làm lại được @VMRuiz đã nhận 1414 ngày trước và không có pull request nào đang mở. Đang mở
scrapinghub/python-scrapinghub#169 · 8 bình luận · 2 reaction · 4 người được giao ·
-
Add retry logic to Job Tag Update functionCó thể đã có người làm @AdrianAtZyte đã nhận 66 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
-
KeyError: 'status' when trying to schedule spiderCó thể đã có người làm @AdrianAtZyte đã nhận 64 ngày trước. Đang mởenhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 30/100
scrapinghub/python-scrapinghub#156 · 6 bình luận ·
Tất cả issue của scrapinghub/python-scrapinghub
Issue tương tự
-
[19.0] pos_sale: settling an order with a 0 down payment line crashes (reading 'reward_id') and leaves a wrong amount dueCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 79/100
developmentseed/titiler-covjson#164 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
awslabs/visual-asset-management-system#2164 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
MakazhanAlpamys/Soup#3589 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
channels status reports the wrong Enabled value for Feishu instances and default-enabled WebSocketĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 1 ngày