xref: /f-stack/doc/F-Stack_Nginx_APP_Guide.md (revision 45438af0)
1# F-Stack Nginx APP Guide
2
3F-Stack is an open source network framework based on DPDK. F-Stack supports standard Nginx as HTTP framework which means all web application based on HTTP can easily use F-Stack.
4
5## How does Nginx use F-Stack?
6
7  Nginx APP is in `app/nginx-1.11.10` directory.
8
9```
10
11                                                        +--------+
12                         +------------------------+     |
13                            channel: socketpair         |
14                         +------------------------+     |  signal(reload, quit..)
15                                                        |
16                                                        |
17                                              +---------v--------+
18                                              |                  |
19                             +----------------+  master process  +---------------+
20                             |                |                  |               |
21                             |  channel       +----------+-------+               |
22                             |                           |              channel  |
23                             |                  channel  |                       |
24                             |                           |                       |
25                   +---------+----------+     +----------+--------+    +---------+--------+
26first one to start |                    |     |                   |    |                  |
27 last one to exit<-+   primary worker   |     |  secondary worker |    | secondary worker |
28                   |                    |     |                   |    |                  |
29                   +--------------------+     +-------------------+    +------------------+
30                   +--------+  +-------+      +--------+  +-------+
31                   |        |  |       |      |        |  |       |
32                   | fstack |  |channel|      | fstack |  |channel|
33                   |  main  |  | event |      |  main  |  | event |
34                   |  loop  |  |thread |      |  loop  |  |thread |
35                   | thread |  |       |      | thread |  |       |
36                   |        |  |       |      |        |  |       |
37                   +--------+  +-------+      +--------+  +-------+
38                    woker       loop:          worker      loop:
39                   process      handle        process      handle
40                    cycle      channel         cycle      channel
41                                event                      event
42
43```
44
45- spawn primary worker firstly, and then wait for primary startup, continue to spawn secondary workers.
46
47- worker process has 2 threads. main thread: ff_init();ff_run(worker_process_cycle), channel thread: loop(handle channel event).
48
49Note that:
50
51- the `reload` is not graceful, service will still be unavailable during the process of reloading.
52
53- necessary modifies in nginx.conf:
54
55```
56    user  root; # root account is necessary.
57    fstack_conf f-stack.conf;  # path of f-stack configuration file, default: $NGX_PREFIX/conf/f-stack.conf.
58    worker_processes  1; # should be equal to the lcore count of `dpdk.lcore_mask` in f-stack.conf.
59
60    events {
61        worker_connections  102400; # increase
62        use kqueue; # use kqueue
63    }
64
65    sendfile off; # sendfile off
66```
67
68## Nginx compiling
69	./configure --prefix=/usr/local/nginx_fstack --with-ff_module
70	make
71	make install
72
73