1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-16 00:00:07 +01:00
libwebsockets/minimal-examples/http-server/minimal-http-server-smp
Andy Green b3131fdfdd cmakelist: Augean Stables refactor
Establish a new distributed CMake architecture with CMake code related to
a source directory moving to be in the subdir in its own CMakeLists.txt.
In particular, there's now one in ./lib which calls through to ones
further down the directory tree like ./lib/plat/xxx, ./lib/roles/xxx etc.

This cuts the main CMakelists.txt from 98KB -> 33KB, about a 66% reduction,
and it's much easier to maintain sub-CMakeLists.txt that are in the same
directory as the sources they manage, and conceal all the details that that
level.

Child CMakelists.txt become responsible for:

 - include_directories() definition (this is not supported by CMake
   directly, it passes it back up via PARENT_SCOPE vars in helper
   macros)

 - Addition child CMakeLists.txt inclusion, for example toplevel ->
   role -> role subdir

 - Source file addition to the build

 - Dependent library path resolution... this is now a private thing
   in the child CMakeLists.txt, it just passes back any adaptations
   to include_directories() and the LIB_LIST without filling the
   parent namespace with the details
2020-05-27 08:40:12 +01:00
..
mount-origin lws logo: update minimal examples 2020-03-06 04:46:39 +00:00
CMakeLists.txt cmakelist: Augean Stables refactor 2020-05-27 08:40:12 +01:00
localhost-100y.cert travis: h2spec integration 2018-04-26 15:27:02 +08:00
localhost-100y.key travis: h2spec integration 2018-04-26 15:27:02 +08:00
minimal-http-server-smp.c windows: pthreads 2020-04-07 14:05:21 +01:00
README.md docs: adjust lost image links 2018-09-19 10:22:21 +08:00

lws minimal http server with multithreaded service

Lws supports multithreaded service... build lws with -DLWS_MAP_SMP=<max number of threads>, the default is 1. If nonzero, some extra pthreads locking is built into lws and it supports multiple independent service threads.

lws-smp-overview

When an incoming connection is accepted, it is bound to the pt with the lowest current wsi count, to keep the load on the threads balanced. Only the pt the wsi is bound to can service the thread, so although there can be as many wsi being serviced simultaneously as there are service threads, a wsi can only be service by the pt it is bound to.

The effectiveness of the scalability depends on the load. Here is an example of roughly what can be expected

lws-smp-example

build

 $ cmake . && make

usage

 $ ./lws-minimal-http-server-smp
[2018/03/07 17:44:20:2409] USER: LWS minimal http server SMP | visit http://localhost:7681
[2018/03/07 17:44:20:2410] NOTICE: Creating Vhost 'default' port 7681, 1 protocols, IPv6 on
[2018/03/07 17:44:20:2411] NOTICE:   Service threads: 10

Visit http://localhost:7681 and use ab or other testing tools