cpprestsdk icon indicating copy to clipboard operation
cpprestsdk copied to clipboard

A quick way to a multithreaded listener

Open guteksan opened this issue 4 years ago • 6 comments

Hi, I am testing this library comparing it to other similar C++ REST libraries available. I noticed that most of them offer a quick way of specifying the number of threads handling the incoming requests, for example, for restbed it is:

settings->set_worker_limit(4);

for others libraries, it is equally easy. I didn't find such easy option for this library, however. Can you indicate how to achieve this with cpprestsdk?

guteksan avatar Apr 09 '20 13:04 guteksan

Just use bellow code can call it at the beginning.

#include <pplx/threadpool.h>

crossplat::threadpool::initialize_with_threads(4)

laoshanxi avatar Apr 15 '20 12:04 laoshanxi

When using the VCPKG x64-windows-static version, VS 2019 cannot find the function:

error LNK2001: unresolved external symbol "public: static void __cdecl crossplat::threadpool::initialize_with_threads(unsigned __int64)" (?initialize_with_threads@threadpool@crossplat@@SAX_K@Z)

MINIONBOTS avatar May 15 '20 11:05 MINIONBOTS

"crossplat::threadpool::initialize_with_threads(4)" is used for Linux platform.

on Windows, I think you do not need to setup a threadpool, by my understanding, the thread is created dynamiclly when there have new request, and there have no initial thread pool, the implementation is different with Linux.

laoshanxi avatar May 16 '20 01:05 laoshanxi

thank you for the explanaion!

MINIONBOTS avatar May 18 '20 07:05 MINIONBOTS

"crossplat::threadpool::initialize_with_threads(4)" is used for Linux platform.

on Windows, I think you do not need to setup a threadpool, by my understanding, the thread is created dynamiclly when there have new request, and there have no initial thread pool, the implementation is different with Linux.

for windows, how to have a pool biggern than 40?

YANG797476 avatar Dec 10 '21 12:12 YANG797476

for windows, it has dynmaic backlog but we still can set MinimumDynamicBacklog / MaximumDynamicBacklog Subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\AFD\Parameters

Value name:EnableDynamicBacklog Value data: 00000001

Value name:MinimumDynamicBacklog Value data: 00000040

Value name:MaximumDynamicBacklog Value data: 00001000

Value name:DynamicBacklogGrowthDelta Value data: 00000010

YANG797476 avatar Dec 13 '21 00:12 YANG797476