Commit Graph

265 Commits

Author SHA1 Message Date
Valentin Bartenev
912a49c609 Reduced number of critical log levels. 2018-03-05 17:32:50 +03:00
Max Romanov
babf67712e Removed unwanted assertions. 2018-02-20 19:00:30 +03:00
Valentin Bartenev
24d07cfdd2 Made nxt_assert() statements to be compiled only with debug. 2018-02-09 19:07:55 +03:00
Valentin Bartenev
fc496c19ac Changed the default number of spare processes to 0. 2018-02-09 19:06:53 +03:00
Igor Sysoev
11d5206866 Router: fixed freed memory access race condition. 2018-02-08 16:51:49 +03:00
Andrey Zelenkov
949ba262cc Style fixes. 2018-02-07 15:34:42 +03:00
Max Romanov
d2c85a2d9e Fixed processing of application response in router.
If the first buffer contained only header and there were other buffers in chain,
those buffers were not processed.  In particular, this broke Perl application
responses with empty body.
2018-02-07 13:47:04 +03:00
Alexander Borisov
960962ddce Added Perl support. 2018-01-31 15:47:00 +03:00
Max Romanov
9cd4fdbdb7 Introducing extended app process management.
- Pre-fork 'processes.spare' application processes;
- fork more processes to keep 'processes.spare' idle processes;
- fork on-demand up to 'processes.max' count;
- scale down idle application processes above 'processes.spare' after
  'processes.idle_timeout';
- number of concurrently started application processes also limited by
  'processes.spare' (or 1, if spare is 0).
2018-01-29 16:17:36 +03:00
Sergey Kandaurov
771e9d3cc3 Fixed formatting in nxt_sprintf() and logging. 2018-01-24 15:16:33 +03:00
Sergey Kandaurov
67c64a99fb Using size_t for the field width type of the "%*s" specifier. 2018-01-24 15:16:32 +03:00
Igor Sysoev
ecba3d80f9 Fixing memory leak introduced in changeset 5817734dd9b9. 2017-12-28 20:08:15 +03:00
Igor Sysoev
9a6d3c5775 HTTP keep-alive connections support. 2017-12-28 16:01:06 +03:00
Igor Sysoev
497faf1b9a Changed nxt_mp_retain() and nxt_mp_release() interfaces. 2017-12-28 16:01:06 +03:00
Max Romanov
47bc1c53d6 Implementing worker stop after limits.requests. 2017-12-27 17:48:53 +03:00
Max Romanov
5196cf4d50 Rescheduling of pending request after configured timeout.
New optional configuration parameter introduced: limits.reschedule_timeout.
Default value 1 second.  In the case when request is written to the port
socket 'in advance', it is called 'pending'.

On every completed request, the head of pending request is checked against
reschedule timeout.  If this request waiting for execution longer than
timeout, it is cancelled, new port selected for this request.
2017-12-27 17:48:04 +03:00
Max Romanov
baa8c9387b Fixing code style. 2017-12-27 17:47:42 +03:00
Max Romanov
bef2ec483e Fixing application timeout.
Application timeout limits maximum time of worker response in processing
particular request.  Not including the time required to start worker,
time in request queue etc.
2017-12-27 17:47:18 +03:00
Max Romanov
ab138c9166 Changing worker selection precedence.
This patch increase precedence of non-started worker over busy worker.

1. idle worker;
2. start new worker;
3. busy worker, but can accept request in advance;
2017-12-27 17:46:39 +03:00
Max Romanov
89c0f7c5db Implementing the ability to cancel request before worker starts processing it. 2017-12-27 17:46:17 +03:00
Valentin Bartenev
8830d73261 HTTP parser: reworked header fields handling. 2017-12-25 17:04:22 +03:00
Max Romanov
392abd03e5 Restoring apps in case of reconfiguration error. 2017-12-25 16:24:54 +03:00
Igor Sysoev
80e8ce8322 A number of engine connections is decreased on connection close. 2017-11-27 17:52:28 +03:00
Max Romanov
fc6520d722 Keep application worker until response for all requests received. 2017-10-19 17:37:26 +03:00
Igor Sysoev
0833074f30 Fixed the bug introduced in the previous changeset. 2017-10-19 17:22:33 +03:00
Igor Sysoev
67c066b026 Router: fixed segfault after configuration change. 2017-10-18 18:05:47 +03:00
Igor Sysoev
09ef66d39c Storing memory cache slot hint inside nxt_sockaddr_t. 2017-10-17 16:22:38 +03:00
Valentin Bartenev
e4bea2c75c Optimized application type handling. 2017-10-10 19:15:08 +03:00
Max Romanov
00ecf713e3 Port message fragmentation supported.
- Each sendmsg() transmits no more than port->max_size payload data.
- Longer buffers are fragmented and send using multiple sendmsg() calls.
- On receive side, buffers are connected in chain.
- Number of handler calls is the same as number of nxt_port_socket_write()
  calls.
- nxt_buf_make_plain() function introduced to make single plain buffer from
  the chain.
2017-10-04 15:03:45 +03:00
Max Romanov
0faecee609 Optimized request<->app link allocation.
Only purpose of request<->app link instance is to be enqueued in application
requests queue.

It is possible to avoid request<->app link allocation from memory pool in
case when spare application port is available.  Instance from local stack
can be used to prepare and send message to application.
2017-10-04 15:03:03 +03:00
Max Romanov
85e485776b Using port 'post' facility to proxy remove pid message to workers.
Remove pid proxying to worker engines implementation was originally
overcomplicated.  Memory pool and 2 engine posts (there and back again) are
optimized out and replaced with band new nxt_port_post() call.
2017-10-04 15:01:15 +03:00
Max Romanov
730f5a9dd9 Using request mem pool for req<->app link.
Request <-> application link structure (nxt_req_app_link_t) used to register
the request in application request queue (nxt_app_t.requests) and generate
application-specific port message.

Now it is allocated from request pool.  This pool created for request parsing
and used to allocate and store information specific to this request.
2017-10-04 15:00:35 +03:00
Max Romanov
a4b5b5d45d Fixed error generation during request processing.
Request can be processed in thread different from the thread where the
connection originally handled.

Because of possible racing conditions, using original connection structures
is unsafe.  To solve this, error condition is registered in 'ra' (request <->
application link) and traversed back to original connection thread where
the error message can be generated and send back to client.
2017-10-04 15:00:05 +03:00
Max Romanov
6a64533fa3 Introducing use counters for port and app. Thread safe port write.
Use counter helps to simplify logic around port and application free.

Port 'post' function introduced to simplify post execution of particular
function to original port engine's thread.

Write message queue is protected by mutex which makes port write operation
thread safe.
2017-10-04 14:58:47 +03:00
Max Romanov
414d508e04 Using engine memiory pool for port write allocations.
To allow use port from different threads, the first step is to avoid using
port's memory pool for temporary allocations required to send data through
the port.  Including but not limited by:
  - buffers for data;
  - send message structures;
  - new mmap fd notifications;

It is still safe to use port memory pool for incoming buffers allocations
because recieve operation bound to single thread.
2017-10-04 14:58:13 +03:00
Max Romanov
4ae76249ed Fixing memory leak when handling remove pid message.
Worker threads ports need to receive 'remove pid' message to properly handle
application process exit case and finish requests processed by particular
application worker.  Main process send 'remove pid' notification to service
thread port only and this message must be 'proxied' to other running engines.

Separate memory pool created for this message.  For each engine structure
required to post message to engine allocate from the pool using 'retain'
allocation method.  After successfull post structure will be freed using
'release' method.  To completely destroy poll one more 'release' should be
called to release initial reference count.

I'm afraid this should be simplified using good old malloc() and free() calls.
2017-10-04 14:57:29 +03:00
Igor Sysoev
bfa808d689 Event engine memory cache for nxt_sockaddr_t.
Introducing event engine memory cache and using the cache for
nxt_sockaddr_t structures.
2017-09-27 19:22:59 +03:00
Valentin Bartenev
45c1d41f34 Removed fibers from compilation.
It's not used anyway, but breaks building with musl.

This closes issue #5 on GitHub.
2017-09-22 16:42:42 +03:00
Max Romanov
838d9946ac Introducing named port message handlers to avoid misprints. 2017-09-15 20:30:34 +03:00
Max Romanov
1449e27cb4 Fixing memory leak of request parse context. 2017-09-15 20:30:29 +03:00
Max Romanov
0bec14878e Introducing application timeout. 2017-09-15 20:30:24 +03:00
Valentin Bartenev
90ae152ce0 Fixed port handlers arrays. 2017-09-15 14:38:22 +03:00
Igor Sysoev
7c1db30994 Router: more logical code order change.
Updating the router engines list before posting jobs to worker thread
engines is more logical because worker threads may exit after the posting.
However, the previous code was safe because an engine is freed by
the router main thread after worker its thread has exited.
2017-09-15 12:27:24 +03:00
Igor Sysoev
309ba5abf2 Router: fixed segmentation fault.
The router process exited abnormally on reconfiguration if number
of worker threads had been decreased on the previous reconfiguration.
Besides the list of router engines should be updated only after a new
configuration joints have been prepared for all engines.
2017-09-14 22:30:38 +03:00
Igor Sysoev
72c3e08158 Router: worker threads should quit only if the main thread has
requested this.
2017-09-14 19:53:25 +03:00
Igor Sysoev
4d5e39e8c1 Fixed textual socket name lengths and Unix domain sockaddr length. 2017-09-14 18:16:22 +03:00
Max Romanov
d87a4fb642 Moving body data before headers for PHP POST.
PHP SAPI tries to read body for POST request before registering
header-specific variables. For other methods, read_post_body() called by SAPI
after variables registration.

This closes #10 issue on GitHub.
2017-09-07 16:39:31 -07:00
Igor Sysoev
58907888e5 Style fixes. 2017-09-06 02:30:55 +03:00
Max Romanov
f0723995a7 Fixing request id logging. 2017-09-05 15:56:37 -07:00
Max Romanov
0f9f0ca522 Fixing racing condition on app port release/request.
Application free ports is a queue (double linked list) protected with mutex.
After successfull request parsing, each router thread (1) tries to get port
from this list. If this list is empty, (2) start worker request posted to main
router thread. Another thread may release port between (1) and (2).

This fix adds an attempt to get port from free ports list at the beginning of
start worker action in main thread.
2017-09-05 15:56:35 -07:00