summaryrefslogtreecommitdiff
path: root/proxy_await.c
Commit message (Collapse)AuthorAgeFilesLines
* proxy: add request and buffer memory limitsdormando2023-03-261-0/+2
| | | | | | | | | | | | | | | | | | Adds: mcp.active_req_limit(count) mcp.buffer_memory_limit(kilobytes) Divides by the number of worker threads and creates a per-worker-thread limit for the number of concurrent proxy requests, and how many bytes used specifically for value bytes. This does not represent total memory usage but will be close. Buffer memory for inbound set requests is not accounted for until after the object has been read from the socket; to be improved in a future update. This should be fine unless clients send just the SET request and then hang without sending further data. Limits should be live-adjustable via configuration reloads.
* proxy: allow workers to run IO optionallydormando2023-02-241-3/+6
| | | | | | | | | | | | | | | | | `mcp.pool(p, { dist = etc, iothread = true }` By default the IO thread is not used; instead a backend connection is created for each worker thread. This can be overridden by setting `iothread = true` when creating a pool. `mcp.pool(p, { dist = etc, beprefix = "etc" }` If a `beprefix` is added to pool arguments, it will create unique backend connections for this pool. This allows you to create multiple sockets per backend by making multiple pools with unique prefixes. There are legitimate use cases for sharing backend connections across different pools, which is why that is the default behavior.
* proxy: add mcp.await_logerrors()dormando2023-01-271-2/+48
| | | | | | | Logs any backgrounded requests that resulted in an error. Note that this may be a temporary interface, and could be deprecated in the future.
* proxy: fix stats deadlock caused by await codedormando2023-01-201-4/+4
| | | | | | | | | | | - specifically the WSTAT_DECR in proxy_await.c's return code could potentially use the wrong thread's lock This is why I've been swapping c with thread as lock/function arguments all over the code lately; it's very accident prone. Am reasonably sure this causes the deadlock but need to attempt to verify more.
* proxy: clean logic around lua yieldingdormando2023-01-121-1/+2
| | | | | | We were duck typing the response code for a coroutine yield before. It would also pile random logic for overriding IO's in certain cases. This now makes everything explicit and more clear.
* core: simplify background IO APIdormando2023-01-111-0/+4
| | | | | | | | - removes unused "completed" IO callback handler - moves primary post-IO callback handlers from the queue definition to the actual IO objects. - allows IO object callbacks to be handled generically instead of based on the queue they were submitted from.
* proxy: log time now relative to resp lifetimedormando2023-01-051-0/+7
| | | | | | | | | | | | | | | | | | | | | | | Originally I envisioned taking an inbound request object, tagging it with the time, and at the very end of a function logging is called. This would give you the total time of the "backend" part of a request. On rethinking, the timing information that's most useful in the proxy's perspective is the time it takes for a response to happen + the status of a response. One request may generate several sub-responses and it is impossible to check the timing of each of those and log outliers. You now cannot get the total time elapsed in a function anymore, but I believe that is less useful information to the user of a proxy. The best picture of latency will still be from the client, and response latency can educate the proxy on issues with backends. resp:elapsed() has been added as a compromise; it returns the elapsed microseconds that a response took, so you can add the time together and get an approximation of total time (if running req/resp's sequentially). This change also means that calling mcp.await() and waiting for multiple responses will give the timing of each sub-response accurately.
* proxy: fix crash in await during SIGHUP reloadsdormando2023-01-021-1/+1
| | | | | | | | | - The await return process uses the "main" VM to move the response into the table we will eventually return to the user. - During the reload routine a nil can be left on the top of the main VM stack. - Safest to just use top-relative indexing for most cases where we use the main VM and aren't explicitly clearing the stack beforehand.
* proxy: add mcp.AWAIT_BACKGROUNDdormando2022-12-011-2/+54
| | | | | | mcp.await(request, pools, 0, mcp.AWAIT_BACKGROUND) will, instead of waiting on any request to return, simply return an empty table as soon as the background requests are dispatched.
* proxy: add proxy_await_active statdormando2022-12-011-0/+2
| | | | | | | proxy_req_active shows the number of active proxy requests, but if those proxy requests make sub-requests via mcp.await() they are not accounted for. This gives the number of await's active, but not the total number of in-flight async requests.
* proxy: add mcp.await FASTGOOD flagdormando2022-09-271-0/+11
| | | | returns early on a hit, else waits for N non-error responses.
* proxy: update mcmc and calling conventionsdormando2022-09-021-1/+1
| | | | | | | upstream fixes: mcmc would return OK to garbage responses, which was probably causing issues in the past. This does remove the MCMC_CODE_MISS and replace it with MCMC_CODE_END.
* proxy: fix mcp.await() when using extended argsdormando2022-07-241-8/+14
| | | | | | was checking the third lua arg, popping it, then likely never finding the fourth arg. now checks fourth arg first and pops it, then works backwards.
* proxy: replace proxycmds stream with proxyreqsdormando2022-04-081-10/+1
| | | | | | | | | delete the magic logging and require mcp.log_req* be used if you want those types of entries to appear. keeps a separate data stream from "proxyuser" just in case that's useful. proxycmds wasn't able to get enough context to autogenerate useful log lines, so I'd rather not have it in there at all.
* proxy: mcp.log_req* API interfacedormando2022-04-081-0/+4
| | | | | | Lua level API for logging full context of a request/response. Provides log_req() for simple logging and log_reqsample() for conditional logging.
* proxy: allow await() to be called recursivelydormando2022-03-021-10/+12
| | | | | | | | previously mcp.await() only worked if it was called before any other dispatches. also fixes a bug if the supplied pool table was key=value instead of an array-type table.
* proxy: hacky method of supporting noreply/quietdormando2022-03-011-0/+21
| | | | | | | | | | | | | | | | avoids sending the response to the client, in most cases. works by stripping the noreply status from the request before sending it along, so the proxy itself knows when to move the request forward. has sharp edges: - only looking at the request object that's actually sent to the backend, instead of the request object that created the coroutine. - overriding tokens in lua to re-set the noreply mode would break the protocol. So this change helps us validate the feature but solidifying it requires moving it to the "edges" of processing; before the coroutine and after any command assembly (or within the command assembly).
* proxy: pull chunks into individual c filesdormando2022-02-181-0/+343
now's a good time to at least shove functional subsections of code into their own files. Some further work to clearly separate the API's will help but looks not too terrible. Big bonus is getting the backend handling code away from the frontend handling code, which should make it easier to follow.