Giter Club home page Giter Club logo

Comments (4)

thed636 avatar thed636 commented on May 19, 2024

Hi!

My use is also sporadic and I also dont really care about the callback.

You may use an empty body lambda as a continuation of the operation in this case.

Given this use scenario, I'm finding that I need to ioc.restart/ioc.run to actually move jobs along
after an ozo::execute.

Well, that is how Boost.Asio works. A user runs an event-loop to execute asynchronous operations and handle events. So without any operations in its queue, the io_context stops. The usually asynchronous program runs event-loop once and works in terms of asynchronous operations and continuations. Sometimes synchronous programs need to use asynchronous API. In that case, there are two choices. The first one - run event-loop in a separate thread and use synchronisation primitives like future. The second - run event-loop in the same thread right after the asynchronous operation started to proceed with. In the second case, restart is needed due to the io_context behaviour. In the case of fire-and-forget for synchronous application, the thirst case with a dedicated thread for the io_context::run() is the only option.

I am not using a work_guard currently. I had thought the connection_pool would do the equivalent for me without having to
burn cpu on an empty loop like work_guard.

Do you have any evidence of burning CPU on an empty cycle without any event or operation posted into the event loop?

If you have any suggestions would you please let me know?

I'd recommend learning a little bit more about Boost.Asio and its concepts, since it looks like there is some misunderstanding for the library API and how it works. So first of all, just try to check a hypothesis about CPU burning.

Hope that helps.

from ozo.

mvphilip avatar mvphilip commented on May 19, 2024

Hello Thank you for the response. I am aware of the coroutine use model. My confusion was on the connection pool and ownership. I had thought the connection pool would keep the context alive. And for this:

Do you have any evidence of burning CPU on an empty cycle without any event or operation posted into the event loop?

Yes and no on this. I am not using threading in my code. So to keep an io_context under a work_guard non-blocking I would need to add a thread. Its not burning cpu but it is using a thread. As I mentioned, I wasnt sure if the resource pool wasnt already doing something to keep the io_context alive already.

But you've answered my question. We need to fully manage the life cycle of the io context outside of ozo.

Thank you again

from ozo.

thed636 avatar thed636 commented on May 19, 2024

Hi!

I had thought the connection pool would keep the context alive.

The connection pool is designed as a context-free entity because we had a negative experience with a context-bound connection pool, especially with multithreading asynchronous applications with one-io_context-per-thread configuration. So the present configuration is the most universal to give a user freedom of making choice.

Its not burning cpu but it is using a thread.

For asynchronous application, this is the only way to execute several control flows simultaneously. So if you care about resources I'd suggest using the asynchronous model for the application.

I am aware of the coroutine use model.

You may use the most generic callback-continuation model. In case of sophisticated operations, I'd suggest using some syntactic sugar as boost::asio::coroutine which models stackless coroutine and allow the linear representation of asynchronous operation without any additional context-switch mechanisms as boost::coroutine.

Best regards.

from ozo.

mvphilip avatar mvphilip commented on May 19, 2024

Thank you again Sergei.

-mp

from ozo.

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.