Commit Graph
100 Commits
Author SHA1 Message Date
Max Romanov 630ec3f1ec Using compiler capability to generate dependencies.
This closes #58 issue on GitHub.
2017-12-01 16:28:06 +03:00
Max Romanov 1add36a7ee Using --ld-opt when linking modules. 2017-11-29 18:49:08 +03:00
Max Romanov 3781950bad Introducing python virtualenv configuration.
New parameter 'home' for python application allows to configure
application-specific virtualenv path.

This closes #15 issue on GitHub.
2017-11-29 18:48:55 +03:00
Max Romanov ec411569e7 Fixing build on Solaris. 2017-11-02 15:32:46 +03:00
Max Romanov 6bbed85899 Fixing Coverity warnings.
CID 200496
CID 200494
CID 200490
CID 200489
CID 200483
CID 200482
CID 200472
CID 200465
2017-11-20 17:08:29 +03:00
Max Romanov fa76ea700f Fixing racing condition in request.msgs usage. 2017-10-27 11:05:37 +03:00
Max Romanov 1d11f8cfbb Fixing Go program crash.
Go request registration should be removed before C request memory freed.

C request address used as a key in Go map.  Freed memory can be instantly
reused for other request and older request registration should removed at this
point to avoid collisions.
2017-10-27 11:05:22 +03:00
Max Romanov 51396fea83 Checking the result of shared memory buffer allocation.
This closes #57 issue on GitHub.
2017-10-25 15:09:07 +03:00
Max Romanov c8a8a7c212 Fixing Go package build.
Go package build was broken by change 365:28b2a468be43.
2017-10-19 18:20:08 +03:00
Max Romanov fc6520d722 Keep application worker until response for all requests received. 2017-10-19 17:37:26 +03:00
Max Romanov b3aab8c66f Filtering process to keep connection.
- Main process should be connected to all other processes.
- Controller should be connected to Router.
- Router should be connected to Controller and all Workers.
- Workers should be connected to Router worker thread ports only.

This filtering helps to avoid unnecessary communication and various errors
during massive application workers stop / restart.
2017-10-19 17:37:19 +03:00
Max Romanov 6031c63225 Introducing mmap_handler to count references to shared memory.
"All problems in computer science can be
                           solved by another level of indirection"

                                                   Butler Lampson

Completion handlers for application response buffers executed after
sending the data to client.  Application worker can be stopped right
after send response buffers to router.  Worker stop causes removal
of all data structures for the worker.

To prevent shared memory segment unmap, need to count the number of
buffers which uses it.  So instead of direct reference to shared
memory, need to reference to intermediate 'handler' structure with
use counter and pointer to shared memory.
2017-10-19 17:37:02 +03:00
Max Romanov 6532e46465 Supporting concurrent shared memory fd receive in router.
Two different router threads may send different requests to single
application worker.  In this case shared memory fds from worker
to router will be send over 2 different router ports.  These fds
will be received and processed by different threads in any order.

This patch made possible to add incoming shared memory segments in
arbitrary order.  Additionally, array and memory pool are no longer
used to store segments because of pool's single threaded nature.

Custom array-like structure nxt_port_mmaps_t introduced.
2017-10-19 17:36:56 +03:00
Max Romanov 6fd465f9d2 Introducing src_pid for mmap header for accurate buf completion.
This allows to use shared memory to communicate with main process.

This patch changes shared memory segment format and breaks compatibility
with older modules.
2017-10-19 17:36:45 +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 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 e44401a0bb Introducing process use counter.
This helps to decouple process removal from port memory pool cleanups.
2017-10-04 15:02:11 +03:00
Max Romanov f869bf1b02 Return error codes for port_hash operations. 2017-10-04 15:02:00 +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 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
Max Romanov ba31199786 Removing mem_pool from port_hash interface.
Memory pool is not used by port_hash and it was a mistake to pass it into
'add' and 'remove' functions.  port_hash enrties are allocated from heap.
2017-10-04 14:57:56 +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
Max Romanov 2ae0449262 Checking mallopt() during configure.
mallopt() is absent on Alpine musl.
2017-09-25 17:53:10 +03:00
Max Romanov 4f7e00ef34 Fixing shared memory thread safety issue.
Do not reuse shared memory segment with different port until this segment
successfully received and indexed on other side. However, segment can be used
to transfer data via the port it was sent at any time.
2017-09-18 17:35:24 +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
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
Max Romanov 789a101e99 Decalring clean and dist targets as .PHONY. 2017-09-07 16:38:05 -07:00
Max Romanov 999de31e25 Spreading user validation for php and go apps. 2017-09-06 08:59:18 -07:00
Max Romanov 05f93d931b Fixed go package installation instructions. 2017-09-05 22:31:57 -07:00
Max Romanov 76f3d7435f Added software installation instructions for CentOS. 2017-09-05 18:04:46 -07: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
Max Romanov c937b8434a Double connection close attempt fix. 2017-09-05 10:22:46 -07:00
Max Romanov 1429cacd17 Using CSTRZ mapping type for go executable. 2017-09-05 10:22:45 -07:00
Max Romanov f1685e371f Introducing working_directory directive for applications. 2017-09-05 10:22:44 -07:00
Max Romanov ac7218e335 Introducing install & uninstall Makefile targets. 2017-08-31 11:42:13 -07:00
Max Romanov 6eb4a41364 Multiplexing different requests in single app port. 2017-08-31 11:42:12 -07:00
Max Romanov fc687e0508 Default value 1 for number of workers. 2017-08-31 11:42:11 -07:00
Max Romanov e06872e2f2 Avoid nxt_port_mmap_header_t redefinition warning. 2017-08-30 14:34:31 -07:00
Max Romanov d3f19d98ca Avoid nxt_go_process_t redefinition warning. 2017-08-30 12:08:29 -07:00
Max Romanov a33145d614 ListenAndServe changed to be compatible with http.ListenAndServe. 2017-08-30 11:50:33 -07:00
Max Romanov 9537821f3f Send remote address to go application. 2017-08-30 11:50:29 -07:00
Max Romanov 9791b09ce3 Fixed pid_file pattern misprint introduced in 231:6832cdee961e. 2017-08-30 11:50:16 -07:00
Max Romanov 92f3b85298 The process type enum exposed to go module. 2017-08-29 14:18:00 -07:00
Max Romanov 6de7cc8634 Fixed debug message broken in e8da77a2c293. 2017-08-29 14:17:59 -07:00
Max Romanov 5b879f0e2b Using NXT_GO variable instead of explicit go. 2017-08-29 11:37:49 -07:00
Max Romanov 52ae0e69c1 Store and use NXT_LIBRT for go module. 2017-08-29 11:33:35 -07:00
Max Romanov 73dc76b0bf Separation of module prerequisites for 'all' target in Makefile.
To avoid using sed -i.
2017-08-29 11:33:34 -07:00
Max Romanov 39a6a4c973 Request body read state implemented.
With specific timeout and buffer size settings.
2017-08-11 18:04:04 +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 162afe4719 RPC: peer pid special value -1 may be used if pid is unknown. 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 f23f985899 Runtime processes protected with mutex. 2017-08-02 13:22:07 +03:00
Max Romanov 021a84019f Freed mmap memory filled with 0xA5. 2017-08-02 13:22:03 +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 bcf99f87e2 Using port rpc in controller->router configuration update. 2017-08-02 13:20:57 +03:00
Max Romanov 82c0304ab8 Using port rpc in router->master start worker request. 2017-08-02 13:20:53 +03:00
Max Romanov c93d2c7623 Include build/Makefile into main Makefile. 2017-08-02 13:18:04 +03:00
Max Romanov f2e9afdf42 Port RPC interface introduced.
Usage:
1. Register handlers in incoming port with nxt_port_rpc_register_handler().
2. Use return value as a stream identifier for next nxt_port_socket_write().
2017-08-02 13:14:31 +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 a7ef8481fc Added make target 'golang-nginext-install' to install precompiled go package. 2017-08-02 13:01:54 +03:00
Max Romanov 83d7ab38ac Using old-style packed attribute specification for compatibility. 2017-08-02 13:01:54 +03:00
Max Romanov 057c2526ee Assign current request id to prevent port memory release. 2017-07-25 16:18:31 +03:00
Max Romanov 5a756647ff Using engine task to avoid racing condition. 2017-07-25 16:18:31 +03:00
Max Romanov 316c77a9de Fixed building on Solaris by Sun C. 2017-07-25 16:18:31 +03:00
Max Romanov 6b6fefa497 Request-app link introduced to prevent mp destroy for penging requests.
nxt_req_conn_link_t still used for lookup connection by request id.
New nxt_req_app_link_t (ra) allocated from conn->mem_pool using mp_retain().
ra stored in app->requests if there is no free worker to process request.
2017-07-18 00:21:28 +03:00
Max Romanov 31e5992f88 Using correct task for engine post. 2017-07-18 00:21:18 +03:00
Max Romanov 8ad2c3fd3a Work queue thread assertions. Reset thread after fork. 2017-07-18 00:21:17 +03:00
Max Romanov 803855138c Mem pool cleanup introduced.
Used for connection mem pool cleanup, which can be used by buffers.
Used for port mem pool to safely destroy linked process.
2017-07-18 00:21:16 +03:00
Max Romanov eb675f2d78 Port allocation and destroy changed. Worker process stop introduced. 2017-07-18 00:21:14 +03:00
Max Romanov 47b359388c Python: typo fixed in string processing shortcut. 2017-07-18 00:21:13 +03:00
Max Romanov 288fa85431 Array elements reallocation fixed. 2017-07-12 20:32:22 +03:00
Max Romanov 48afadfe7c Memory pool debug enabled with NXT_DEBUG_ALLOC define. 2017-07-12 20:32:20 +03:00
Max Romanov 7d3fd1c96c Single allocation for app conf and name. 2017-07-12 20:32:19 +03:00
Max Romanov a97a5e8a0b Go: worker initialization. READY message to master. 2017-07-12 20:32:18 +03:00
Max Romanov 51bbdd3338 PHP SAPI: dynamic worker initialization. 2017-07-12 20:32:17 +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 e41425bb1f Router: connection destroy sequence fixed. 2017-07-07 18:16:14 +03:00
Max Romanov 9a402ea83d Taken counter initialized for new pages.
Fixed crash in nxt_mp_get() when pages re-used and 'taken' contains initial
'map' value '0xFFFFFFFF'.
2017-07-07 16:01:34 +03:00
Max Romanov e58f4ef0d0 Memory pool thread safety checks in DEBUG build and usage fixes. 2017-07-07 16:01:34 +03:00
Max Romanov e15b975e9d Work queue thread safety checks for DEBUG build. 2017-07-07 16:01:34 +03:00
Max Romanov 5529e9f0d1 Python initialization moved from master to worker application. 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 61008a7c0b Cosmetic changes to remove some annoying valgrind messages. 2017-07-07 16:01:34 +03:00
Max Romanov 264ae98d49 Using engine's task instead of listen's task. 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 c56d2af3bc Router: read configuration from port.
Controller: stub to send configuration from POST body "as is" to router.
2017-07-06 18:38:51 +03:00
Max Romanov d28d502aa5 PHP SAPI: SERVER_NAME, SERVER_PORT and REMOTE_ADDR introduced. 2017-07-05 13:32:02 +03:00
Max Romanov 41e2678110 Python WSGI: SERVER_NAME, SERVER_PORT fixed, REMOTE_ADDR introduced.
Shortcut: do not iterate over String (or Bytes) return object.
Call 'close()' for return object (if present).
2017-07-05 13:31:53 +03:00
Max Romanov f3107f3896 Complex target parser copied from NGINX.
nxt_app_request_header_t fields renamed:
- 'path' renamed to 'target'.
- 'path_no_query' renamed to 'path' and contains parsed value.
2017-07-05 13:31:45 +03:00
Max Romanov 44b3ad17f4 Double buf completion call on connection timeout fixed. 2017-06-26 19:58:43 +03:00
Max Romanov d62e6c3b18 PHP post body processing fixed, default index name introduced. 2017-06-26 19:58:43 +03:00