xref: /f-stack/doc/F-Stack_Nginx_APP_Guide.md (revision b14f72a4)
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                                                    +--------+
1240600211Slogwang                                                    |
1340600211Slogwang+------------------------+                          |
1440600211Slogwang   channel: socketpair                              |  signal(reload, quit..)
1540600211Slogwang+------------------------+                          |
1640600211Slogwang                                                    |
1740600211Slogwang                                          +---------v--------+
1840600211Slogwang                                          |                  |
1940600211Slogwang                         +----------------+  master process  +---------------+
2040600211Slogwang                         |                |                  |               |
2140600211Slogwang                         |  channel       +----------+-------+               |
2240600211Slogwang                         |                           |              channel  |
2340600211Slogwang                         |                  channel  |                       |
2440600211Slogwang                         |                           |                       |
2540600211Slogwang               +---------+----------+     +----------+--------+    +---------+--------+
2640600211Slogwang               |                    |     |                   |    |                  |
2740600211Slogwang               | ff primary process |     |  worker process   |    |  worker process  |
2840600211Slogwang               |                    |     |                   |    |                  |
2940600211Slogwang               +--------------------+     +-------------------+    +------------------+
30*b14f72a4Slogwang                ff_init(primary)          +--------+  +-------+
3140600211Slogwang                loop:                     |        |  |       |
3240600211Slogwang                 handle channel event     | fstack |  |channel|
3340600211Slogwang                                          |  main  |  | event |
3440600211Slogwang                                          |  loop  |  |thread |
3540600211Slogwang                                          | thread |  |       |
3640600211Slogwang                                          |        |  |       |
3740600211Slogwang                                          +--------+  +-------+
3840600211Slogwang                                           woker       loop:
3940600211Slogwang                                          process      handle
4040600211Slogwang                                           cycle      channel
4140600211Slogwang                                                       event
42a9643ea8Slogwang
4340600211Slogwang```
44a9643ea8Slogwang
45*b14f72a4Slogwang- spawn an extra process ff primary: ff_init(primary);loop(handle channel event).This process doesn't handle SIGQUIT.
46*b14f72a4Slogwang
47*b14f72a4Slogwang- worker process has 2 threads. main thread: ff_init(secondary);ff_run(worker_process_cycle), channel thread: loop(handle channel event).
48a9643ea8Slogwang
4940600211SlogwangNote that:
5040600211Slogwang- supported nginx signals: reload(HUP)/reopen(USR1)/stop(TERM).
51a9643ea8Slogwang
5240600211Slogwang- unsupported nginx signals: NGX_CHANGEBIN_SIGNAL(USR2).
53a9643ea8Slogwang
54*b14f72a4Slogwang- when use `nginx -s reload`, you should make sure that `woker_processes` in nginx.conf and f-stack.conf haven't be modified.
55a9643ea8Slogwang
5640600211Slogwang- necessary modifies in nginx.conf:
57a9643ea8Slogwang
5840600211Slogwang```
5940600211Slogwang    user  root; # root account is necessary.
6040600211Slogwang    fstack_conf f-stack.conf;  # path of f-stack configuration file, default: $NGX_PREFIX/conf/f-stack.conf.
6140600211Slogwang	worker_processes  1; # should be equal to the lcore count of `dpdk.lcore_mask` in f-stack.conf.
62a9643ea8Slogwang
63a9643ea8Slogwang	events {
6440600211Slogwang		worker_connections  102400; # increase
65a9643ea8Slogwang		use kqueue; # use kqueue
66a9643ea8Slogwang	}
67a9643ea8Slogwang
68a9643ea8Slogwang	sendfile off; # sendfile off
6940600211Slogwang```
70a9643ea8Slogwang
7140600211Slogwang## Nginx compiling
7240600211Slogwang	./configure --prefix=/usr/local/nginx_fstack --with-ff_module
7340600211Slogwang	make
7440600211Slogwang	make install
75a9643ea8Slogwang
76