Skip to content

Allow handling requests in multiple tasks #798

@denglerchr

Description

@denglerchr

I'm using a Julia webserver to provide some data to a Grafana dashboard. Opening a dashboard immediately sends multiple requests to the server, some of which take >1s to complete, therefore I was trying to make the request handling work in multiple threads, as currently one can see the panels being filled with a delay one after the other. I couldnt figure it out though, it seems that HTTP.jl requires the response of one request being sent before accepting a new request. My guess is it can't be done currently and would require new functionality, if Im wrong please correct me. Therefore I would like to propose to add this functionality in some way for some future version of HTTP.
I could imagine something like this

# julia -t 8
using HTTP

const requestChannel = Channel{HTTP.Request}(8)

# "autorespond" option doesnt exist yet
HTTP.serve(; autorespond = false) do request
    put!(requestChannel, request)
    return nothing
end

function handleRequests()
    while true
        request = take!(requestChannel)
        sleep(5) # work being done
        response = HTTP.Response(200)
        HTTP.respond(request, response) # this function doesnt exist
    end
end

for i = 1:8
    Threads.@spawn handleRequests()
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions