Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why size is no affect in map? #158

Closed
wonb168 opened this issue Dec 19, 2022 · 1 comment
Closed

why size is no affect in map? #158

wonb168 opened this issue Dec 19, 2022 · 1 comment

Comments

@wonb168
Copy link

wonb168 commented Dec 19, 2022

I split the urls myself,cost about 6 minutes,

rst=[]
size=10
for i in range(98):# 5m 58.8s
    if i%size==0:
        print(i,i+size)
        rs = (grequests.get(u) for u in urls[i:i+size])
        rst.extend(grequests.map(rs))

But, if use size in map, 20minusts ago, no output, I killed it:

rs = (grequests.get(u) for u in urls)
rst=grequests.map(rs,size=10)

Why?
And how to speed it, thanks!

@spyoungtech
Copy link
Owner

The behavior you're seeing is probably because one or more of your requests is hanging. Add the timeout keyword argument the request to be sure one request does not hang up your entire request list.

Can't reproduce this using httpbin.org -- must be a reliability problem with the server you're contacting.

In my own testing, map(rs, size=10) is significantly faster.

urls = [f'https://httpbin.org/status/200' for _ in range(100)]
>>> timeit.timeit(sized_map, globals=globals(), number=1)
4.341320300009102
>>> timeit.timeit(manual_map, globals=globals(), number=1) 
6.858147199964151

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants