-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for asynchronous callbacks #26
Comments
AFAIK from HTTP API perspective, watches are done via blocking queries. Ppconsul already supports blocking queries although in a quite limited way. |
Apologies, my initial comment on this issue was not clear and I am still learning all the capabilities of this library. I see from the README and status markdown file that this blocking query is actually there. I was more referring to an enhancements such as you refer to with capabilities for async callbacks, background polling, etc. For example, an application wanting to watch for all updates on a key, prefix, etc and then be notified with the value that has changed. Maybe a mechanism to map watch items to registered observers and then background a query that polls and reschedules watch items? |
Yes, supporting async callbacks or something similar would be great. It's quite pity there is no standard C++ approach for this. From implementation perspective I can only think about something based on |
When is this enhancement planned ?. Can you please update on the same. I see above solution to use boost async is that the only option ?. |
@bkannadassan it’s not planned yet. The problem is that there is no standard mechanism in C++ to implement it and regardless of the way I chose there will be projects that can’t integrate with it smoothly. I don’t want to write event based engine by myself thus I need to either use some framework like Boost.Asio or allow user to integrate Ppconsul with an event engine they use. I’m talking about Boost.Asio for particular reasons: it’s widely used and I’ve already build a lot of successful projects with it. It’s flexible enough to allow Ppconsul to be integrated into any project that’s not based on Boost.Asio for a cost of one extra thread that will handle Ppconsul IO. I’d like to hear how ppconsul users would like to use asynchronous callbacks and what their application uses as event engine so I can think about providing the best integration experience. |
The Apache Mesos project has it's own custom library for dealing with asynchronicity: https://github.com/apache/mesos/tree/master/3rdparty/libprocess The ideal integration for us would allow us to implement one or more interfaces using our async library, and pass those implementation to ppconsul for it to use. Off the top of my head, the operations we would provide implementations for:
These would be straightforward for us to implement and pass into ppconsul, and it would then not need any of its own threads nor would it need to block a caller's thread. We use Futures but we can wire those up ourselves on top of callbacks that ppconsul invokes. I would also suspect that many users don't care about having multiple threadpools and will want some default implementation that they can pass in, like a threadpool + Boost.Asio implementation. @oliora asynchronous library composition is an interesting area, would love to hear your thoughts! |
Ppconsul uses libcurl easy API which is blocking so it’s not possible to make Ppconsul truly asynchronous (i.e. not blocking the execution thread for the request time) without complete rewrite of the network part. Otherwise, Ppconsul can only be changed to use a thread pool under the hood (either internal or passed from outside). This will still give some benefit for the user perhaps. It’s an interesting idea to have async library abstracted via an interface but in reality I don’t think this gonna work. Many users want ppconsul as a ready to use solution not a building block thus ppconsul has to provide its own networking implementation anyway. Also it may not be feasible to come up with interface for async calls that still allows to use different libraries effectively. I’m leaning more toward using boost.asio + boost.beast and leave it up to users to integrate it into their event loop. Worst case they will run one extra thread for ppconsul and dispatch completion events from there to their own event loop. @bmahler which async io library do you use in your projects? |
I've seen a bunch of Rust projects which are runtime independent, i.e, you bring in your own runtime (e.g., event loop). libprocess is certainly one approach here, as is I'd still hesitate to include boost as a dependency, unless it's clear that the libraries are header only or will be included in the next C++ standard. Boost is heavy! |
One of the few good references I've found on the I/O free library idea is here: https://sans-io.readthedocs.io/
@oliora yeah, what I had suggested implies ppconsul would use a Sans-I/O style HTTP library (for example, the Sans-IO page links to a python implementation) composed with the user provided I/O library. I'm not sure if there are some good sans-I/O style HTTP libraries in C/C++. libcurl does have an async API and from the looks of the examples, it seems like it does let you drive the I/O. In this example, you need to do the polling your own way, and it will perform the non blocking reads/writes when you tell it to: https://curl.haxx.se/libcurl/c/curl_multi_perform.html
I mainly work on Apache Mesos and it uses libprocess. It's really only used by Mesos.
Right, I think you would want one or more default implementations available to users if you were to go this route (e.g. thread pool + libev + libcurl async API, or some other implementation combo). I noted this in my earlier message.
@SamuelMarks Do you have any links? |
Sure, here's a good example: https://github.com/sozu-proxy/lapin |
Is there currently any plan to add support for watches on the various types in consul?
Currently have the need to watch key and or keyprefix for update/creation/delete. I'm willing to help looking at how to add this. I have previously used the java support for this behavior from the orbitz consul-client.
The text was updated successfully, but these errors were encountered: