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 7*28e10b57Sfengbojiang(姜凤波) Nginx APP is in `app/nginx-1.16.1` 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 453d7e1b6bSchenwei## What's Different? 463d7e1b6bSchenwei### New directives: 473d7e1b6bSchenweiAll the directives below are available only when ```NGX_HAVE_FSTACK``` is defined. 488461d8a7S陈威``` 498461d8a7S陈威 Syntax: kernel_network_stack on | off; 508461d8a7S陈威 Default: kernel_network_stack off; 518461d8a7S陈威 Context: http, server 523d7e1b6bSchenwei 538461d8a7S陈威 Determines whether server should run on kernel network stack or fstack. 548461d8a7S陈威``` 558461d8a7S陈威 563d7e1b6bSchenwei``` 573d7e1b6bSchenwei Syntax: proxy_kernel_network_stack on | off; 583d7e1b6bSchenwei Default: kernel_network_stack off; 593d7e1b6bSchenwei Context: http, stream, mail, server 606d206da2Slogwang 613d7e1b6bSchenwei Determines whether proxy should go through kernel network stack or fstack. 623d7e1b6bSchenwei``` 63a9643ea8Slogwang 643d7e1b6bSchenwei``` 653d7e1b6bSchenwei Syntax: schedule_timeout time; 66f8aeb5ebS陈威 Default: schedule_timeout 30ms; 6755d550aeS陈威 Context: main 68a9643ea8Slogwang 693d7e1b6bSchenwei Sets a time interval for polling kernel_network_stack. The default value is 30 msec. 703d7e1b6bSchenwei``` 713d7e1b6bSchenwei 723d7e1b6bSchenwei### Command-line `reload` 733d7e1b6bSchenweithe `reload` is not graceful, service will still be unavailable during the process of reloading. 743d7e1b6bSchenwei 753d7e1b6bSchenwei### Necessary modifies in nginx.conf: 7640600211Slogwang``` 7740600211Slogwang user root; # root account is necessary. 7840600211Slogwang fstack_conf f-stack.conf; # path of f-stack configuration file, default: $NGX_PREFIX/conf/f-stack.conf. 7940600211Slogwang worker_processes 1; # should be equal to the lcore count of `dpdk.lcore_mask` in f-stack.conf. 80a9643ea8Slogwang 81a9643ea8Slogwang events { 8240600211Slogwang worker_connections 102400; # increase 83a9643ea8Slogwang use kqueue; # use kqueue 84a9643ea8Slogwang } 85a9643ea8Slogwang 86a9643ea8Slogwang sendfile off; # sendfile off 8740600211Slogwang``` 88a9643ea8Slogwang 8940600211Slogwang## Nginx compiling 9040600211Slogwang ./configure --prefix=/usr/local/nginx_fstack --with-ff_module 9140600211Slogwang make 9240600211Slogwang make install 93a9643ea8Slogwang 94