xref: /f-stack/doc/F-Stack_Nginx_APP_Guide.md (revision 8461d8a7)
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                                                        +--------+
1263fb3d1fSlogwang                         +------------------------+     |
1363fb3d1fSlogwang                            channel: socketpair         |
1463fb3d1fSlogwang                         +------------------------+     |  signal(reload, quit..)
1540600211Slogwang                                                        |
1640600211Slogwang                                                        |
1740600211Slogwang                                              +---------v--------+
1840600211Slogwang                                              |                  |
1940600211Slogwang                             +----------------+  master process  +---------------+
2040600211Slogwang                             |                |                  |               |
2140600211Slogwang                             |  channel       +----------+-------+               |
2240600211Slogwang                             |                           |              channel  |
2340600211Slogwang                             |                  channel  |                       |
2440600211Slogwang                             |                           |                       |
2540600211Slogwang                   +---------+----------+     +----------+--------+    +---------+--------+
2663fb3d1fSlogwangfirst one to start |                    |     |                   |    |                  |
2763fb3d1fSlogwang last one to exit<-+   primary worker   |     |  secondary worker |    | secondary worker |
2840600211Slogwang                   |                    |     |                   |    |                  |
2940600211Slogwang                   +--------------------+     +-------------------+    +------------------+
3068458806S陈威                   +--------------------+     +-------------------+
3168458806S陈威                   |                    |     |                   |
3268458806S陈威                   |   fstack,kernel    |     |   fstack,kernel   |
3368458806S陈威                   |     and channel    |     |     and channel   |
3468458806S陈威                   |     loop thread    |     |     loop thread   |
3568458806S陈威                   |                    |     |			  |
3668458806S陈威                   +--------------------+     +-------------------+
3768458806S陈威                    woker process cycle        woker process cycle
38a9643ea8Slogwang
3940600211Slogwang```
40a9643ea8Slogwang
4163fb3d1fSlogwang- spawn primary worker firstly, and then wait for primary startup, continue to spawn secondary workers.
42b14f72a4Slogwang
4368458806S陈威- a major addition to the worker process is fstack-handling:ff_init();ff_run(worker_process_cycle); worker_process_cycle(handle channel/host/fstack event).
44a9643ea8Slogwang
45*8461d8a7S陈威- a new directive `kernel_network_stack` :
46*8461d8a7S陈威```
47*8461d8a7S陈威    Syntax: kernel_network_stack on | off;
48*8461d8a7S陈威    Default: kernel_network_stack off;
49*8461d8a7S陈威    Context: http, server
50*8461d8a7S陈威    This directive is available only when ```NGX_HAVE_FSTACK``` is defined.
51*8461d8a7S陈威    Determines whether server should run on kernel network stack or fstack.
52*8461d8a7S陈威```
53*8461d8a7S陈威
5440600211SlogwangNote that:
556d206da2Slogwang
5663fb3d1fSlogwang- the `reload` is not graceful, service will still be unavailable during the process of reloading.
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