3 ms·
I have a question. I want to adopt oatpp.io, but I'm using a synchronous database driver mongo-cxx-driver. Can I still benefit from oat++'s coroutine? Also, wh
by billconan 8y ago
I have a question. I want to adopt oatpp.io, but I'm using a synchronous database driver mongo-cxx-driver. Can I still benefit from oat++'s coroutine? Also, when using coroutine, will the server be a single-thread process? or it will be a multiple thread process with each thread using coroutines (to fully utilize the cpu)?
If my server wants to visit third party rest APIs in an asynchronized way, what's the best asynchronized library to choose to make use of coroutine?
- lganzzzo 8y agoThank you for the question. ----------------------------------------------------------------------------- // I want to adopt oatpp.io, but I'm using a synchronous database driver mongo-cxx-driver. - Unfortunately no - if your driver has only synchronous API you can use it with multithreaded oatpp only. ----------------------------------------------------------------------------- // Also, when using coroutine, will the server be a single-thread process? // or it will be a multiple thread process with each thread using coroutines (to fully utilize the cpu) - Yes, it will be a multiple thread process with each thread using coroutines. You can configure how many threads should run the AsyncHttpConnectionHandler. Number of threads is passed to the AsyncHttpConnectionHandler constructor. Also you may tweak it in compile time via option: "-D OATPP_ASYNC_HTTP_CONNECTION_HANDLER_THREAD_NUM_DEFAULT=<num of threads>" You have to play with this parameter in order to achieve best performance. In most cases on : - Linux it's value should be (<num of CPUs> - 1). - On MacOS it's value should be 2. ----------------------------------------------------------------------------- // If my server wants to visit third party rest APIs in an asynchronous way, // what's the best asynchronized library to choose to make use of coroutine? - Native way to do it is to use oatpp ApiClient https://oatpp.io/docs/component/api-client https://oatpp.io/docs/component/api-client it provides two declarations: - API_CALL("GET", "/resource", getResource) ///< Example of API call - API_CALL_ASYNC("GET", "/resource", getResourceAsync) ///< Example of Async API call Also there is an example project with the full example how to make asynchronous calls to rest APIs https://github.com/oatpp/oatpp-examples/tree/master/tls-libressl https://github.com/oatpp/oatpp-examples/tree/master/tls-libr... There is no README currently in this example, but I gonna add asap.