cpprestsdk icon indicating copy to clipboard operation
cpprestsdk copied to clipboard

http_listener hangs when sending more than 40 requests at the same time

Open mohamedAlaaK opened this issue 6 years ago • 5 comments

On ubuntu 16.04. I am using http_listener to handle some json requests. threadpool default number of threads is 40 and when i send more than 40 requests at the same time from a curl command the server just hangs forever and doesn't respond to any further requests. I did set the number of threads at the program start to say 100 and now it can handle up to 100 requests at the same time. sending more than 100 will make it hang again.

is there some functionality i am missing here ?

it would be nice if the thread pool is dynamically expandable or some sort of a queue holding requests and threads operate on that queue.

mohamedAlaaK avatar May 27 '19 14:05 mohamedAlaaK

I had the same question and it seems the server hangs at task http_request::extract_json().get().

wangtao9 avatar May 30 '19 06:05 wangtao9

Does https://github.com/microsoft/cpprestsdk/issues/1147#issuecomment-499414735 help?

garethsb avatar Jun 06 '19 09:06 garethsb

I met the same issue before, because handle_rest() occupy one thread and http_request::extract_json().get() will request another thread to recieve message, if there is no more thread in pool, it will hang forever.

laoshanxi avatar Aug 21 '19 01:08 laoshanxi

If i had to wait for some response and perform further steps only after the request is completed, then what to do in that case . Also many cpprest blogs demonstrate to wait on the request object.

https://mariusbancila.ro/blog/2017/11/19/revisited-full-fledged-client-server-example-with-c-rest-sdk-2-10/

Below is my code snippet and it seems to work for first few requests and then hangs. I dnt have access to server side code and seems server side code is there for many years. I am just writing the client side code

pplx::task<web::http::http_response> request_task = client.request(request);
        try
        {        
            web_response = request_task.get();
            result = true;

        }
        catch (const std::exception& ex)
        {
            string_t errorMessage;
            ErrorMsg = L"Can't reach the confighub agent. " + utility::conversions::to_string_t(ex.what());
        }
        catch (...)
        {
            return result;
        }

sahnnu avatar Aug 08 '22 12:08 sahnnu

If i had to wait for some response and perform further steps only after the request is completed, then what to do in that case . Also many cpprest blogs demonstrate to wait on the request object.

https://mariusbancila.ro/blog/2017/11/19/revisited-full-fledged-client-server-example-with-c-rest-sdk-2-10/

Below is my code snippet and it seems to work for first few requests and then hangs and it retrieves after few minutes . I dnt have access to server side code and seems server side code is there for many years. I am just writing the client side code

pplx::task<web::http::http_response> request_task = client.request(request);
        try
        {        
            web_response = request_task.get();
            result = true;

        }
        catch (const std::exception& ex)
        {
            string_t errorMessage;
            ErrorMsg = L"Can't reach the confighub agent. " + utility::conversions::to_string_t(ex.what());
        }
        catch (...)
        {
            return result;
        }

@garethsb can you pls tell you changed the code at client side or server side.

sahnnu avatar Aug 08 '22 12:08 sahnnu