xref: /f-stack/doc/F-Stack_Nginx_APP_Guide.md (revision 63fb3d1f)
1a9643ea8Slogwang# F-Stack Nginx APP Guide
2a9643ea8Slogwang
3a9643ea8SlogwangF-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.
4a9643ea8Slogwang
5a9643ea8Slogwang## How does Nginx use F-Stack?
6a9643ea8Slogwang
7a9643ea8Slogwang  Nginx APP is in `app/nginx-1.11.10` directory.
8a9643ea8Slogwang
940600211Slogwang```
10a9643ea8Slogwang
1140600211Slogwang                                                        +--------+
12*63fb3d1fSlogwang                         +------------------------+     |
13*63fb3d1fSlogwang                            channel: socketpair         |
14*63fb3d1fSlogwang                         +------------------------+     |  signal(reload, quit..)
1540600211Slogwang                                                        |
1640600211Slogwang                                                        |
1740600211Slogwang                                              +---------v--------+
1840600211Slogwang                                              |                  |
1940600211Slogwang                             +----------------+  master process  +---------------+
2040600211Slogwang                             |                |                  |               |
2140600211Slogwang                             |  channel       +----------+-------+               |
2240600211Slogwang                             |                           |              channel  |
2340600211Slogwang                             |                  channel  |                       |
2440600211Slogwang                             |                           |                       |
2540600211Slogwang                   +---------+----------+     +----------+--------+    +---------+--------+
26*63fb3d1fSlogwangfirst one to start |                    |     |                   |    |                  |
27*63fb3d1fSlogwang last one to exit<-+   primary worker   |     |  secondary worker |    | secondary worker |
2840600211Slogwang                   |                    |     |                   |    |                  |
2940600211Slogwang                   +--------------------+     +-------------------+    +------------------+
30*63fb3d1fSlogwang                   +--------+  +-------+      +--------+  +-------+
31*63fb3d1fSlogwang                   |        |  |       |      |        |  |       |
32*63fb3d1fSlogwang                   | fstack |  |channel|      | fstack |  |channel|
33*63fb3d1fSlogwang                   |  main  |  | event |      |  main  |  | event |
34*63fb3d1fSlogwang                   |  loop  |  |thread |      |  loop  |  |thread |
35*63fb3d1fSlogwang                   | thread |  |       |      | thread |  |       |
36*63fb3d1fSlogwang                   |        |  |       |      |        |  |       |
37*63fb3d1fSlogwang                   +--------+  +-------+      +--------+  +-------+
38*63fb3d1fSlogwang                    woker       loop:          worker      loop:
39*63fb3d1fSlogwang                   process      handle        process      handle
40*63fb3d1fSlogwang                    cycle      channel         cycle      channel
41*63fb3d1fSlogwang                                event                      event
42a9643ea8Slogwang
4340600211Slogwang```
44a9643ea8Slogwang
45*63fb3d1fSlogwang- spawn primary worker firstly, and then wait for primary startup, continue to spawn secondary workers.
46b14f72a4Slogwang
47*63fb3d1fSlogwang- worker process has 2 threads. main thread: ff_init();ff_run(worker_process_cycle), channel thread: loop(handle channel event).
48a9643ea8Slogwang
4940600211SlogwangNote that:
506d206da2Slogwang
51*63fb3d1fSlogwang- the `reload` is not graceful, service will still be unavailable during the process of reloading.
52a9643ea8Slogwang
5340600211Slogwang- necessary modifies in nginx.conf:
54a9643ea8Slogwang
5540600211Slogwang```
5640600211Slogwang    user  root; # root account is necessary.
5740600211Slogwang    fstack_conf f-stack.conf;  # path of f-stack configuration file, default: $NGX_PREFIX/conf/f-stack.conf.
5840600211Slogwang    worker_processes  1; # should be equal to the lcore count of `dpdk.lcore_mask` in f-stack.conf.
59a9643ea8Slogwang
60a9643ea8Slogwang    events {
6140600211Slogwang        worker_connections  102400; # increase
62a9643ea8Slogwang        use kqueue; # use kqueue
63a9643ea8Slogwang    }
64a9643ea8Slogwang
65a9643ea8Slogwang    sendfile off; # sendfile off
6640600211Slogwang```
67a9643ea8Slogwang
6840600211Slogwang## Nginx compiling
6940600211Slogwang	./configure --prefix=/usr/local/nginx_fstack --with-ff_module
7040600211Slogwang	make
7140600211Slogwang	make install
72a9643ea8Slogwang
73