Giter Club home page Giter Club logo

Comments (13)

mksm avatar mksm commented on July 16, 2024

I believe there's an individual socket pool for each Easy handle. If you use Multi, it will keep a shared connection pool. Or reutilize the Easy handle by setting the url again and calling #perform.

from curb.

drbrain avatar drbrain commented on July 16, 2024

Switching this example to use Curb::Multi I see the same behavior (multiple sockets created).

The man page for curl_easy_perform() says:

   You can do any amount of calls to curl_easy_perform(3) while using  the
   same handle. If you intend to transfer more than one file, you are even
   encouraged to do so. libcurl will then attempt to re-use the same  con-
   nection for the following transfers, thus making the operations faster,
   less CPU intense and using less network resources. Just note  that  you
   will have to use curl_easy_setopt(3) between the invokes to set options
   for the following curl_easy_perform.

Which leads me to believe that Curl::Easy#perform should behave as I expect.

from curb.

taf2 avatar taf2 commented on July 16, 2024

this should fix the issue. http://github.com/taf2/curb/commit/73e11030c9debfc6c51f32e6aef4f597281cf6db

It keeps the original multi handle around between invocations.

I added two benchmarks in bench/curb_easy.rb and bench/nethttp_test.rb

here's the results for me:

time ruby bench/curb_easy.rb
Duration 0.059045 seconds

real 0m0.083s
user 0m0.019s
sys 0m0.014s

time ruby bench/nethttp_test.rb
Duration 0.063115 seconds

real 0m0.731s
user 0m0.406s
sys 0m0.070s

from curb.

mksm avatar mksm commented on July 16, 2024

Just to point it out, libcurl already uses a multi handle to perform a easy handle even if you don't manually add the handle.

from curb.

taf2 avatar taf2 commented on July 16, 2024

I think the issue with curb here is different... Unless libcurl provides away to get at that multi handle? For each easy request curb was creating a new multi handle, effectively throwing away any open connections. Now instead, when calling the curb easy perform it will reuse it's internal multi handle... Hope that makes sense?

from curb.

mksm avatar mksm commented on July 16, 2024

I'm wondering why create a multi for each easy handle if libcurl does that by itself inside easy_perform?

from curb.

taf2 avatar taf2 commented on July 16, 2024

curl_easy_perform blocks the whole ruby interpreter. To avoid the blocking and have libcurl play nice with ruby, all IO is run through rb_thread_select. In order to expose that kind of IO a multi interface was necessary... Unless there is an interface to expose what select method libcurl uses or access the easy handle's internal multi interface?

from curb.

mksm avatar mksm commented on July 16, 2024

Did some testing in 1.8.7 and 1.9.1 and it does some evil blocking indeed. Since we don't have access to libcurl's select or internal multi, a suggestion would be to fit rb_thread_schedule() in a callback and get rid of multi and the fds hassle.

from curb.

taf2 avatar taf2 commented on July 16, 2024

you mean for example have a libcurl callback on the easy handle such as on_progress or another that calls maybe rb_thread_schedule or even yields ?

from curb.

mksm avatar mksm commented on July 16, 2024

Yup, but according to libcurl docs, on_progress callback does not seem to be a good choice since it keeps being called every second even if there is no transfer running. I've did a quick test by placing rb_thread_schedule inside CURLOPT_WRITEFUNCTION callback and works . I didn't run any benchmark tho.

from curb.

taf2 avatar taf2 commented on July 16, 2024

if there's not transfer running than it's blocked... write function would only be called when data is received?

from curb.

taf2 avatar taf2 commented on July 16, 2024

I really think select is the right thing here, you want the OS to tell you when to idle and when to read/write otherwise let ruby run.

from curb.

taf2 avatar taf2 commented on July 16, 2024

Alright, it's using persistent connections now

from curb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.