xref: /f-stack/doc/F-Stack_Nginx_APP_Guide.md (revision 6d206da2)
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               +--------------------+     +-------------------+    +------------------+
30b14f72a4Slogwang                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
45b14f72a4Slogwang- spawn an extra process ff primary: ff_init(primary);loop(handle channel event).This process doesn't handle SIGQUIT.
46b14f72a4Slogwang
47b14f72a4Slogwang- worker process has 2 threads. main thread: ff_init(secondary);ff_run(worker_process_cycle), channel thread: loop(handle channel event).
48a9643ea8Slogwang
4940600211SlogwangNote that:
50*6d206da2Slogwang- kni couldn't be enabled in this version, because kni is only processed by primary and worker `ff_primary` won't execute `ff_run()`.
51*6d206da2Slogwang
5240600211Slogwang- supported nginx signals: reload(HUP)/reopen(USR1)/stop(TERM).
53a9643ea8Slogwang
5440600211Slogwang- unsupported nginx signals: NGX_CHANGEBIN_SIGNAL(USR2).
55a9643ea8Slogwang
56b14f72a4Slogwang- when use `nginx -s reload`, you should make sure that `woker_processes` in nginx.conf and f-stack.conf haven't be modified.
57a9643ea8Slogwang
5840600211Slogwang- necessary modifies in nginx.conf:
59a9643ea8Slogwang
6040600211Slogwang```
6140600211Slogwang    user  root; # root account is necessary.
6240600211Slogwang    fstack_conf f-stack.conf;  # path of f-stack configuration file, default: $NGX_PREFIX/conf/f-stack.conf.
6340600211Slogwang	worker_processes  1; # should be equal to the lcore count of `dpdk.lcore_mask` in f-stack.conf.
64a9643ea8Slogwang
65a9643ea8Slogwang	events {
6640600211Slogwang		worker_connections  102400; # increase
67a9643ea8Slogwang		use kqueue; # use kqueue
68a9643ea8Slogwang	}
69a9643ea8Slogwang
70a9643ea8Slogwang	sendfile off; # sendfile off
7140600211Slogwang```
72a9643ea8Slogwang
7340600211Slogwang## Nginx compiling
7440600211Slogwang	./configure --prefix=/usr/local/nginx_fstack --with-ff_module
7540600211Slogwang	make
7640600211Slogwang	make install
77a9643ea8Slogwang
78