1d4afb5ceSopenharmony_ci# lws minimal http server with multithreaded service
2d4afb5ceSopenharmony_ci
3d4afb5ceSopenharmony_ciLws supports multithreaded service... build lws with `-DLWS_MAP_SMP=<max number of threads>`, the
4d4afb5ceSopenharmony_cidefault is 1.  If nonzero, some extra pthreads locking is built into lws and it supports multiple
5d4afb5ceSopenharmony_ciindependent service threads.
6d4afb5ceSopenharmony_ci
7d4afb5ceSopenharmony_ci![lws-smp-overview](/doc-assets/lws-smp-ov.png)
8d4afb5ceSopenharmony_ci
9d4afb5ceSopenharmony_ciWhen an incoming connection is accepted, it is bound to the pt with the lowest current wsi
10d4afb5ceSopenharmony_cicount, to keep the load on the threads balanced.  Only the pt the wsi is bound to can service
11d4afb5ceSopenharmony_cithe thread, so although there can be as many wsi being serviced simultaneously as there are
12d4afb5ceSopenharmony_ciservice threads, a wsi can only be service by the pt it is bound to.
13d4afb5ceSopenharmony_ci
14d4afb5ceSopenharmony_ciThe effectiveness of the scalability depends on the load.  Here is an example of roughly what can be expected
15d4afb5ceSopenharmony_ci
16d4afb5ceSopenharmony_ci![lws-smp-example](/doc-assets/lws-smp-example.png)
17d4afb5ceSopenharmony_ci
18d4afb5ceSopenharmony_ci## build
19d4afb5ceSopenharmony_ci
20d4afb5ceSopenharmony_ci```
21d4afb5ceSopenharmony_ci $ cmake . && make
22d4afb5ceSopenharmony_ci```
23d4afb5ceSopenharmony_ci
24d4afb5ceSopenharmony_ci## usage
25d4afb5ceSopenharmony_ci
26d4afb5ceSopenharmony_ci```
27d4afb5ceSopenharmony_ci $ ./lws-minimal-http-server-smp
28d4afb5ceSopenharmony_ci[2018/03/07 17:44:20:2409] USER: LWS minimal http server SMP | visit http://localhost:7681
29d4afb5ceSopenharmony_ci[2018/03/07 17:44:20:2410] NOTICE: Creating Vhost 'default' port 7681, 1 protocols, IPv6 on
30d4afb5ceSopenharmony_ci[2018/03/07 17:44:20:2411] NOTICE:   Service threads: 10
31d4afb5ceSopenharmony_ci```
32d4afb5ceSopenharmony_ci
33d4afb5ceSopenharmony_ciVisit http://localhost:7681 and use ab or other testing tools
34d4afb5ceSopenharmony_ci
35