Open mkiernan opened 3 years ago
Any progress on this? It's really not ideal for C++ applications that needs to use this library automatically spawns 40 threads by default.
This isn't just happening after calling azure::storage::blob_request_options
. Any azure::storage
object triggers this initialize_with_threads
, with 40 threads. Users should have the option to dictate the number of threads allocated for the use of this library.
The threadpool size for the cpprestsdk appears to be fixed at 40. This is an insufficient number of threads for my use case. I'm attempting to use the workaround outlined in: https://github.com/Microsoft/cpprestsdk/issues/428
This works perfectly for standalone situations such as the one outlined here: https://medium.com/@debashishdekanits2015/casablanca-cpprestsdk-5856e7d3724e. However, in my case I'm also building against the azure-storage-cpp library, and this seems to prevent me from setting the threadpool size as it's somehow already initialized before I make the call.
Example code: g++ -o test test.cpp -lazurestorage -lcpprest -lssl -lcrypto -lpthread
libcpprest-dev 2.10.17 azure-storage-cpp: 7.5.0 ubuntu 20.04, gcc 9.3.0
test.cpp:
include <pplx/threadpool.h>
include <was/blob.h>
int main(int argc, char *argv[]) { size_t numThreads = 64; std::cout << "numthreads: " << numThreads << std::endl; crossplat::threadpool::initialize_with_threads(numThreads); std::cout << "pool set" << std::endl; azure::storage::blob_request_options options; } output: numthreads: 64 terminate called after throwing an instance of 'std::runtime_error' what(): the cpprestsdk threadpool has already been initialized Aborted (core dumped)
If I comment out the last line:
// azure::storage::blob_request_options options;
Then it works: ./test numthreads: 64 pool set
(and I can verify at OS level that there are 64 threads created correctly).
So it seems that even though I'm initializing the pool before any other calls, when I make any call into the azure-storage-cpp library anywhere in my code, somehow the library has initialized the pool already, and I'm thus unable to customize the threadcount.
Besides hardwiring the cpprest library to a number >40, is there another way to work around or fix this?