Recently I dusted off the project and started updating some of it's C++ dependencies.. making sure everything was compiling and running.
I am now trying to test the end points.. and getting right up to the point where my server should be returning the object(s) of interest.. but something goes wrong and I am not sure why...
I ended up discovered I had hardcoded the number of connections in the connection pool... at 32! way too high for a macbook air from 2013 (2 cores 4 threads).
but even when I turned down the # of threads to open to 4 and run on the MBA... it still crashes..
I had, out of laziness, kept the promises in use.. but maybe when the batches == 1 I should just avoid futures... but I am a bit worried why it won't properly halt and wait for the futures `.get()` then..?
I will look into your #2 suggestion as well.. thank you
EDIT: bit of background but the queries list is only read.. never modified.. don't know if that helps ease your mind on its usage here.. but I will bump the code building the concatenation to before the async, thanks!
I ended up discovered I had hardcoded the number of connections in the connection pool... at 32! way too high for a macbook air from 2013 (2 cores 4 threads)
No, I don't think so. Hardware threads are different from software threads. So 32 connections (even more) shouldn't be a problem.
Using thread carelessly might very well cause all kinds of misbehavior.
bit of background but the queries list is only read.. never modified.. don't know if that helps ease your mind on its usage here.. but I will bump the code building the concatenation to before the async
You actually do not provide enough code to tell what is going wrong. But calling process_data of single_fetcher directly is certainly a good idea.
Line 5 might be wrong because single_fetcher might be wrongfully passed (shouldn't it be pointer?).
So I took your advice.. modified to remove the future (since when batch_size == 1 , we don't need concurrency) ... and lo' and behold the bug STILL remains.. leading me to believe the problem is likely inside the data fetcher.. or the connection pool code
I may have to throw out the connection pool logic and start from scratch or think of another way to connect 32 concurrent clients
I think my next goal is to learn to use gdb so I can see what is exactly happening
For using a debugger I recommend using an IDE such as CodeBlocks.
Unfortunately debugger don't work well for thread issues. Instead you might want to increase the number of outputs. For determining the order of execution simple output like std::cout << "1\n!; would suffice.
It is quite ambitions to use a framework with a near to no documentation like this...
What are the types here:
1 2
auto proxy_conn = this->tws_conn_pool->get_connection();
auto x = dynamic_cast<TWSConnection*>(proxy_conn.operator->());
Particularly this proxy_conn.operator->() looks kind of weird...
What does get_connection() do? Getting the first free connection something?
When pointer are involved you should check whether they are valid. At least with an assert(x);.
This looks like a possible problem:
1 2 3
x->tws_client.query_matching_tickers(empty_contract_vect, query_vector, first_element, last_element);
std::cout << "THE query is started..." << std::endl;
this->tws_conn_pool->release_connection(std::move(proxy_conn));
When query_matching_tickers(...) uses a thread then release_connection(...) might end the process prematurely.
By the way: You usually (outside a template) don't need this->. The compiler does it for you.