Comments (4)
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.
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.
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.
Thank you again Sergei.
-mp
from ozo.
Related Issues (20)
- C++ 20 Compatible HOT 2
- Stored Procedures Support HOT 8
- Examples for OidMap & Custom types support is sql queries HOT 5
- How to choose C++ type for Postgres built-in types? HOT 5
- Does Ozo support LTREE type HOT 3
- Why are there no INSERT examples, especially with Boost.Hana? HOT 7
- Nested array of custom types support HOT 2
- Does ozo need to fetch all data from postgres before it starts to e.g. push it back to a vector? HOT 2
- Docker hub is limiting pull rate
- How do I define a custom citext type provided by postgres as an extension in code? HOT 2
- I get the error Connection timeout at normal load. HOT 3
- How to use io_context::strand to make queries? HOT 2
- tweaking connection pool to reuse specific connection
- async_connect does not handle socket from libpq properly, fails to connect in some environments HOT 3
- How can I include this library? HOT 2
- c++20 coroutine compatibility HOT 2
- Build errors.. HOT 2
- c++20 support HOT 3
- create an example of calling a stored procedure ?
- It is not clear how to find out the number of affected rows by delete/insert/update operation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ozo.