JuliaWeb / HTTP.jl

HTTP for Julia
https://juliaweb.github.io/HTTP.jl/stable/
Other
626 stars 177 forks source link

Performance degradation vs curl in Julia API #1158

Open AbrJA opened 4 months ago

AbrJA commented 4 months ago

Hi everyone, thanks for your effort in developing this package

Exploring the Oxygen package to build APIs, it is based on your package, I found this:

I run this API locally and I reach about 560 RPS (ab -n1000 -c100 'http://localhost:8001/model')

using Oxygen

@get "/model" function()
    sleep(0.15)
    return json("ok")
end

serve(port = 8001)

When I build another API consuming the previous one, I reach only around 100 RPS even with multithreading (ab -n1000 -c100 'http://localhost:8002/test')

using Oxygen
using HTTP

@get "/test" function()
    response = HTTP.get("http://localhost:8001/model") # sleep(0.15) - Just this line is different
    return json("ok")
end

serve(port = 8002)

Changing this API to use curl instead of HTTP.jl I got a huge improvement, I go from 100 RPS to about 440 RPS

using Oxygen

@get "/test" function()
    response = run(`curl http://localhost:8001/model`) # instead of HTTP.request("GET", "http://localhost:8001/model")
    return json("ok")
end

serve(port = 8002)

Do you have any idea why this is happening?

Thank you for your help,

Abraham

AbrJA commented 2 weeks ago

Using EasyCurl as suggested here I get around 520 RPS

using Oxygen
using EasyCurl

@get "/test" function()
    response = curl_get("http://localhost:8001/model")
    return json("Ok")
end

serve(port = 8002)