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