1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-16 00:00:07 +01:00
libwebsockets/minimal-examples/ws-client/minimal-ws-client-spam
Andy Green 48366de1d1 unix plat: add minimal wsi fd map option
An lws context usually contains a processwide fd -> wsi lookup table.

This allows any possible fd returned by a *nix type OS to be immediately
converted to a wsi just by indexing an array of struct lws * the size of
the highest possible fd, as found by ulimit -n or similar.

This works modestly for Linux type systems where the default ulimit -n for
a process is 1024, it means a 4KB or 8KB lookup table for 32-bit or
64-bit systems.

However in the case your lws usage is much simpler, like one outgoing
client connection and no serving, this represents increasing waste.  It's
made much worse if the system has a much larger default ulimit -n, eg 1M,
the table is occupying 4MB or 8MB, of which you will only use one.

Even so, because lws can't be sure the OS won't return a socket fd at any
number up to (ulimit -n - 1), it has to allocate the whole lookup table
at the moment.

This patch looks to see if the context creation info is setting
info->fd_limit_per_thread... if it leaves it at the default 0, then
everything is as it was before this patch.  However if finds that
(info->fd_limit_per_thread * actual_number_of_service_threads) where
the default number of service threads is 1, is less than the fd limit
set by ulimit -n, lws switches to a slower lookup table scheme, which
only allocates the requested number of slots.  Lookups happen then by
iterating the table and comparing rather than indexing the array
directly, which is obviously somewhat of a performance hit.

However in the case where you know lws will only have a very few wsi
maximum, this method can very usefully trade off speed to be able to
avoid the allocation sized by ulimit -n.

minimal examples for client that can make use of this are also modified
by this patch to use the smaller context allocations.
2019-05-18 12:10:19 +01:00
..
CMakeLists.txt minimal: minimal-ws-client-spam 2018-11-15 10:00:54 +08:00
libwebsockets.org.cer minimal: minimal-ws-client-spam 2018-11-15 10:00:54 +08:00
minimal-ws-client-spam.c unix plat: add minimal wsi fd map option 2019-05-18 12:10:19 +01:00
README.md minimal: minimal-ws-client-spam 2018-11-15 10:00:54 +08:00
selftest.sh minimal: minimal-ws-client-spam 2018-11-15 10:00:54 +08:00

lws minimal ws client SPAM

This connects to libwebsockets.org using the lws-mirror-protocol.

By default is has 10 concurrent connections and connects 100 times.

build

 $ cmake . && make

Commandline Options

Option Meaning
-d Set logging verbosity
--server Use a specific server instead of libwebsockets.org, eg --server localhost. Implies LCCSCF_ALLOW_SELFSIGNED
--port Use a specific port instead of 443, eg --port 7681
-c Amount of concurrent connections
-l Test limit (total number of connections to make)

usage

Just run it, it will repeatedly connect and reconnect to libwebsockets.org until it hits the test limit.

You can also direct it to use the lws test server in tls mode by running that with libwebsockets-test-server -s and running this using, eg

 $ ./lws-minimal-ws-client-spam -c 20 -l 200 --server localhost --port 7681
 $ ./lws-minimal-ws-client-spam
[2018/11/15 09:53:19:9639] USER: LWS minimal ws client SPAM
[2018/11/15 09:53:19:9647] NOTICE: Creating Vhost 'default' (serving disabled), 1 protocols, IPv6 off
[2018/11/15 09:53:19:9695] NOTICE: created client ssl context for default
[2018/11/15 09:53:21:0976] USER: callback_minimal_spam: established (try 10, est 0, closed 0, err 0)
[2018/11/15 09:53:21:1041] USER: callback_minimal_spam: established (try 10, est 1, closed 0, err 0)
[2018/11/15 09:53:21:1089] USER: callback_minimal_spam: established (try 10, est 2, closed 0, err 0)
[2018/11/15 09:53:21:1132] USER: callback_minimal_spam: established (try 10, est 3, closed 0, err 0)
[2018/11/15 09:53:21:1166] USER: callback_minimal_spam: established (try 10, est 4, closed 0, err 0)
[2018/11/15 09:53:21:1531] USER: callback_minimal_spam: established (try 10, est 5, closed 0, err 0)
[2018/11/15 09:53:21:1563] USER: callback_minimal_spam: established (try 10, est 6, closed 0, err 0)
[2018/11/15 09:53:21:1589] USER: callback_minimal_spam: established (try 10, est 7, closed 0, err 0)
[2018/11/15 09:53:21:1616] USER: callback_minimal_spam: established (try 10, est 8, closed 0, err 0)
[2018/11/15 09:53:21:1671] USER: callback_minimal_spam: established (try 10, est 9, closed 0, err 0)
[2018/11/15 09:53:21:3778] USER: callback_minimal_spam: reopening (try 11, est 10, closed 1, err 0)
...