mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-27 07:59:41 +08:00
UDP loop: deadlines in a heap, on a monotonic clock
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ubuntu-latest (wolfSSL) (push) Waiting to run
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ubuntu-latest (wolfSSL) (push) Waiting to run
The loop went through every session three times a turn: for the nearest deadline, to register its sockets with epoll, and for the deadlines come and the sessions ended. A datagram cost as much as the sessions there were, idle ones too. - The deadlines are in a binary heap, the nearest at its top: the wait is until the top, and the sessions timed out are taken from the top down to the first not due. A datagram only moves a session's deadline later, which leaves the heap as it is: the session is looked at again when its old deadline comes, and put back where its deadline is then, once in its timeout however many datagrams it had. A deadline set earlier by a handler goes up the heap. - A session ended is put on a list and let go at the end of the turn, and its sockets are registered with epoll after the loop or a handler had it, not every session every turn. - Deadlines are milliseconds of monotime(), CLOCK_MONOTONIC (the performance counter on Windows), which the time of day being set does not move: before, a clock set back kept sessions for as long, and one set forward ended them all. The loop reads it once a turn, in u->now. With epoll, a datagram costs the same with 20000 idle sessions as with none (38-40 us of the proxy's CPU a round trip, ARM), where it took 59 before. poll() elsewhere still builds its set every turn. Tests: a session heard from every half second lives through two seconds of idle timeout, and ends two seconds after the last datagram. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f69eb13e9a
commit
57818ad497
6 files changed
+266
-48
No files matched your search
+1
-1
@@ -179,7 +179,7 @@ static int dnsforward(struct udploop *u, struct udpsession *ss){
|
||||
if(bindwithrange(param, param->remsock, ¶m->sinsl, param->extport)) continue;
|
||||
param->sinsr = ns[q->server].addr;
|
||||
ss->idle = 0;
|
||||
ss->deadline = time(NULL) + param->srv->timeouts[DNS_TO];
|
||||
ss->deadline = u->now + (uint64_t)param->srv->timeouts[DNS_TO] * 1000;
|
||||
if(q->tcp){
|
||||
/* connected, then written to, as the loop sees it writable */
|
||||
if(param->srv->so._connect(param->sostate, param->remsock, (struct sockaddr *)¶m->sinsr, SASIZE(¶m->sinsr))
|
||||
|
||||
Reference in new issue
Block a user