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

asyncmap computes elements of a lazy sequence within a single task #37863

Open
kernelmethod opened this issue Oct 3, 2020 · 0 comments
Open

Comments

@kernelmethod
Copy link
Contributor

Perhaps not so much a bug as undocumented and potentially undesirable behavior, but:

Issue

When iterating over a lazily-computed sequence such as a generator, asyncmap computes all of the elements of that sequence within a single task. Here's a minimal working example:

taskoid() = objectid(current_task())
seq = (taskoid() for _ in eachline("/path/to/text/file"))
task_ids = asyncmap(seq; ntasks=10) do x
    x
end

At the end of this code, task_ids contains the id of a single task, indicating that every element of seq was computed within the same task.

Expected behavior

It would probably make more sense for the ith element of seq to be calculated by the task that operates on it. This would support some richer ways in which to use asyncmap. For instance, here's an example using HTTP.jl and Transducers.jl to query a list of URLs and report which ones returned a 200 status code:

using HTTP
using Transducers

filtered_responses =
    eachline("urls.txt") |>
    Map(u -> HTTP.get(e); status_exception = false) |>
    Filter(r -> r.status == 200)

asyncmap(filtered_responses; ntasks=5) do r
    println(r.request.target)
end

The current implementation of asyncmap causes each call to HTTP.get to run in the same task, rather than concurrently. It'd probably be preferable for the call to asyncmap above to work more like this:

@sync for _ = 1:5
    @async for r in filtered_responses
        println(r.request.target)
    end
end

Additional info

  • Julia version: 1.5.2
kernelmethod added a commit to kernelmethod/julia that referenced this issue Oct 4, 2020
Add a new test to check whether `asyncmap` computes lazily-generated
sequences withinin a single task, as described by issue JuliaLang#37863.
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

1 participant