Commit Graph

44 Commits

Author SHA1 Message Date
Max Romanov
89b1e88f8f Closing unsent file descriptors from port queue.
After a process exits, all ports linked to it from other processes
should be closed.  All unsent file descriptors in port queue, marked as
"close after send", should be closed to avoid resource leakage.
2020-05-28 12:40:49 +03:00
Igor Sysoev
57e326b411 Introduced chained buffer completion handlers. 2019-11-14 16:39:48 +03:00
Max Romanov
caea9d3c07 Fixing multi-thread port write racing conditions. 2019-08-16 00:48:11 +03:00
Max Romanov
9ea4be7e4e Fixing allocation alignment for port fragments.
All allocated blocks for lvlhash required to be aligned because lower
address bits used for various extra information.  Using unaligned blocks
may cause invalid memory aceess.

This was issue found on buildbot running large configuration tests.
2019-06-28 12:19:48 +03:00
Max Romanov
b96e5fd848 Turning off port read event state after main process fork.
Master port stores two file descriptors and works as a read port on the master
process side.  After a fork, the port switches into write mode and the read
socket closes, but the same event structure is used for the write socket.
However, the inherited structure remained in read state, telling the epoll
engine to use MOD operation instead of ADD.  The patch resets read event
state, so the engine may write using proper ADD operation.
2019-03-25 14:49:28 +03:00
Max Romanov
ddd2e8cc36 Improving port message fragment recognition.
This is required to assemble fragmented messages correctly.  Stream
identifier is unique only for messages generated within a process, but
the (stream, pid) pair should be enough to avoid collisions.  Adding
reply_port seems redundant because it's enough to add stream to a pid.

This closes #199 issue on GitHub.
Thanks to 洪志道 (Hong Zhi Dao).
2019-03-05 15:38:51 +03:00
Max Romanov
42b66ec654 Fixing EAGAIN processing for port message send.
Sending large plain (exceeding port's max_size, not in shared memory) messages
causes message fragmentation.  First message fragment is sent successfully,
but the next fragment may fail with the EAGAIN error.  In this case, the
message has to be pushed back to queue head for additional processing.

Related to #167 issue on GitHub.
2019-03-05 15:38:50 +03:00
Max Romanov
aedb999fe1 Including port message header into message size limit.
Before this fix, large plain message (i.e. configuration) send may fail
with the 'Message too big' error, because internal fragmentation
implementation does not account for 16 byte message header.

This closes #167 issue on GitHub.
2019-03-05 15:38:48 +03:00
Max Romanov
afda14d1f2 Preserving message 'share' field when pushing to queue.
As far as I understand, this field is important to control the number of
buffers send in a single write attempt.  Furthermore, having uninitialized
field is always bad.

This closes #204 issue on GitHub.
Thanks to 洪志道 (Hong Zhi Dao).
2019-02-28 18:03:21 +03:00
Max Romanov
0c917b4d34 Reusing fragmented message buffers.
Fragmented message non-mmap buffer chain not freed nor reused before
this fix.

This closes #206 on GitHub.
Thanks to 洪志道 (Hong Zhi Dao).
2019-02-28 13:39:31 +03:00
Valentin Bartenev
d15b4ca906 Style. 2018-04-05 15:49:41 +03:00
Igor Sysoev
18377ad288 nxt_port_buf_completion() and nxt_sendbuf_completion().
nxt_sendbuf_completion() has been renamed to nxt_port_buf_completion()
and moved to src/nxt_port_socket.c.  nxt_sendbuf_completion0() has been
renamed to nxt_sendbuf_completion().
2018-03-28 19:10:02 +03:00
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
Andrey Zelenkov
949ba262cc Style fixes. 2018-02-07 15:34:42 +03:00
Igor Sysoev
497faf1b9a Changed nxt_mp_retain() and nxt_mp_release() interfaces. 2017-12-28 16:01:06 +03:00
Max Romanov
b59535b22c Removed unused variable assignment.
Found by Coverity (CID 215301).
2017-12-28 15:58:01 +03:00
Max Romanov
89c0f7c5db Implementing the ability to cancel request before worker starts processing it. 2017-12-27 17:46:17 +03:00
Max Romanov
ec411569e7 Fixing build on Solaris. 2017-11-02 15:32:46 +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
439bf7df11 Breaking read loop by nxt_port_read_close().
Port message handler may perform fork() and then close port read file
descriptor and enable write on same event fd.  Next read attempt in this case
may cause different errors in log file.
2017-10-04 15:02:32 +03:00
Max Romanov
ebbe89bd5c Optimized send message allocations.
For empty write queue cases, it is possible to avoid allocation and enqueue
send message structures.  Send message initialized on stack and passed to
write handler.  If immediate write fails, send message allocated from engine
pool and enqueued.
2017-10-04 14:59:35 +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
Igor Sysoev
58907888e5 Style fixes. 2017-09-06 02:30:55 +03:00
Max Romanov
e1e808bd94 Sync flag introduced for port type.
To avoid transfer mmap_msg before new mmap message.
2017-08-11 18:04:04 +03:00
Max Romanov
1b354421c3 Tiny mmap buffers completion fixed.
Small mmap buffers transferred in 'plain' mode and should be freed by sender.
2017-08-11 18:04:04 +03:00
Max Romanov
b150f07e80 Added basic port error handler. 2017-08-02 13:36:29 +03:00
Max Romanov
9367dd2bf8 Implicit port read buffer completion.
To disable implicit completion, handler should reset msg->buf field.
2017-08-02 13:21:32 +03:00
Max Romanov
3812ffd336 Added bit flags to type parameter of nxt_port_socket_write().
NXT_PORT_MSG_LAST     - mark message as last;
NXT_PORT_MSG_CLOSE_FD - close fd right after send;

Type constants altered to include last flag for single buffer messages.

Last sign is critical for coming port RPC layer. Handlers unregistered on last
message. Create sync buffer is not convenient, extra parameter is better.
2017-08-02 13:10:48 +03:00
Max Romanov
eb675f2d78 Port allocation and destroy changed. Worker process stop introduced. 2017-07-18 00:21:14 +03:00
Max Romanov
b0c1e740cf New process port exchange changed. READY message type introduced.
Application process start request DATA message from router to master.
Master notifies router via NEW_PORT message after worker process become ready.
2017-07-12 20:32:16 +03:00
Max Romanov
e15b975e9d Work queue thread safety checks for DEBUG build. 2017-07-07 16:01:34 +03:00
Max Romanov
74cda90e31 Process stop notification from master to all other processes.
New port message type introduced NXT_PORT_MSG_REMOVE_PID. Default handler
removes process description from nxt_runtime_t with all ports, incoming and
outgoing mmaps etc.
2017-07-07 16:01:34 +03:00
Max Romanov
f319220a6c Redirecting buffer completion handler to specific engine.
There is a case in router where we use port in router connection thread.
Buffers are allocated within connection memory pool which can be used only in
this router thread. sendmsg() can be postponed into main router thread and
completion handler will compare current engine and post itself to correct
engine.
2017-07-07 16:01:34 +03:00
Max Romanov
abe0d33329 Increased size of iovec when data passed using shared memory.
Useful for tiny shared memory segment test case.
2017-06-23 19:20:08 +03:00
Max Romanov
3b9aa27625 Added mem_pool pointer member to nxt_port_send_msg_t.
To decouple nxt_port_send_msg_t from port.
2017-06-23 19:20:08 +03:00
Max Romanov
eaf28db46e Moved message size to nxt_port_recv_msg_t for convenience. 2017-06-23 19:20:08 +03:00
Igor Sysoev
f888a5310c Using new memory pool implementation. 2017-06-20 19:49:17 +03:00
Max Romanov
f7b4bdfd89 Using shared memory to send data via nxt_port.
Usage:
    b = nxt_port_mmap_get_buf(task, port, size);
    b->mem.free = nxt_cpymem(b->mem.free, data, size);
    nxt_port_socket_write(task, port, NXT_PORT_MSG_DATA, -1, 0, b);
2017-05-12 20:32:41 +03:00
Igor Sysoev
b379dae85e Port changes. 2017-02-22 15:10:28 +03:00
Igor Sysoev
029942f4eb I/O operations refactoring. 2017-02-22 15:09:59 +03:00
Igor Sysoev
059a864289 Event engines refactoring. 2017-02-07 20:04:56 +03:00
Igor Sysoev
e57b95a923 Process channels have been renamed to ports. 2017-02-01 20:03:45 +03:00