Browse Source

facil.io: use the `FIO_DEDICATED_SYSTEM` implementation (from master) (#3392)

* Update facil.io version + add common setup script

The main relevant difference in the updated facil.io version is the
memory allocator (I wrote a custom memory allocator that should
minimize lock contention).

It's possible to test the new version without the multi-threaded memory
allocator by using:

```sh
export CFLAGS="${CFLAGS} -DFIO_FORCE_MALLOC"
```

I tried testing the dockerfile locally, but couldn’t make it work.

For some reason the vagrant machine refuses to find the tfb command
(`vagrant up` complains with a number of errors as well, this being one
of them).

I might open a separate issue for that, but I’m not sure if it isn’t
something I’m doing wrong.

* Copy app only once

* Test the facil.io `FIO_DEDICATED_SYSTEM` flag (in master)

I hope this isn’t rude of me, but instead of releasing a facil.io
version, I am updating this app to test the effects of the
`FIO_DEDICATED_SYSTEM` flag introduced in [the facil.io master
branch](https://github.com/boazsegev/facil.io/blob/2fb10a91248eb359f1aae
c3f46ecc0c63b043afc/lib/facil/core/facil.c#L192-L204).

facil.io assumes processes are for concurrency and threads are for
parallelism (protection against slow/blocking user code).

However, when deploying facil.io on dedicated systems, this isn’t
always the best design choice. Hence, the `FIO_DEDICATED_SYSTEM` adds
concurrent thread execution into the mix.

I’m not sure if this flag should be enabled on Citrin, but this should
demonstrate this flag’s effects.

* Set workers and threads to utilize threads

* Use numeral settings instead of variable settings

This change is probably temporary, the idea was to divide the cores
between 4 processes (each using threads to utilize the remaining
cores).

* Calculate threads by CPU count

* Make sure we have at least 1 thread...
Bo 7 years ago
parent
commit
ceb7be2f25
2 changed files with 11 additions and 1 deletions
  1. 10 0
      frameworks/C/facil.io/bench_app.c
  2. 1 1
      frameworks/C/facil.io/facil.io.dockerfile

+ 10 - 0
frameworks/C/facil.io/bench_app.c

@@ -49,6 +49,16 @@ static void on_request_json(http_s *h);
 /* handles plain text requests (Hello World) */
 static void on_request_plain_text(http_s *h);
 
+/* *****************************************************************************
+This is the same as setting `FIO_DEDICATED_SYSTEM` compiling the facil.io master
+***************************************************************************** */
+#include "evio.h"
+void defer_thread_wait(pool_pt pool, void *p_thr) {
+  (void)pool;
+  (void)p_thr;
+  evio_wait(500);
+}
+
 /* *****************************************************************************
 The main function
 ***************************************************************************** */

+ 1 - 1
frameworks/C/facil.io/facil.io.dockerfile

@@ -18,4 +18,4 @@ RUN cp -f bench_app.c facil_app/src/app.c
 RUN cd facil_app && make -j build
 
 # Run the app
-CMD ["./facil_app/tmp/demo", "-p", "8080", "-db \"TFB-database\"", "-w", "-1", "-t", "-1"]
+CMD ./facil_app/tmp/demo -p 8080 -db "TFB-database" -w 4 -t $(( CPU_COUNT >4 ? (CPU_COUNT/4) : 1))