2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 14:07:59 +00:00

Limit the number of inactive handles kept for reuse

Instead of growing and never shrinking the list of the inactive
handles (to be reused mostly on the UDP connections), limit the number
of maximum number of inactive handles kept to 64.  Instead of caching
the inactive handles for all listening sockets, enable the caching on on
UDP listening sockets.  For TCP, the handles were cached for each
accepted socket thus reusing the handles only for long-standing TCP
connections, but not reusing the handles across different TCP streams.
This commit is contained in:
Ondřej Surý
2023-08-16 16:30:53 +02:00
parent 1a958b709a
commit f36e118b9a
3 changed files with 18 additions and 1 deletions

View File

@@ -104,6 +104,13 @@ STATIC_ASSERT(ISC_NETMGR_TCP_RECVBUF_SIZE <= ISC_NETMGR_RECVBUF_SIZE,
*/
#define NM_MAXSEG (1280 - 20 - 40)
/*%
* How many isc_nmhandles and isc_nm_uvreqs will we be
* caching for reuse in a socket.
*/
#define ISC_NM_NMHANDLES_MAX 64
#define ISC_NM_UVREQS_MAX 64
/*
* Define ISC_NETMGR_TRACE to activate tracing of handles and sockets.
* This will impair performance but enables us to quickly determine,
@@ -245,6 +252,7 @@ struct isc_nmhandle {
#endif
LINK(isc_nmhandle_t) active_link;
LINK(isc_nmhandle_t) inactive_link;
void *opaque;
isc_job_t job;
@@ -624,6 +632,9 @@ struct isc_nmsocket {
*/
ISC_LIST(isc_nmhandle_t) inactive_handles;
size_t inactive_handles_cur;
size_t inactive_handles_max;
/*%
* 'active' handles and uvreqs, mostly for debugging purposes.
*/

View File

@@ -806,6 +806,8 @@ dequeue_handle(isc_nmsocket_t *sock) {
if (handle != NULL) {
ISC_LIST_DEQUEUE(sock->inactive_handles, handle, inactive_link);
sock->inactive_handles_cur--;
isc_refcount_init(&handle->references, 1);
INSIST(VALID_NMHANDLE(handle));
return (handle);
@@ -913,7 +915,10 @@ nmhandle__destroy(isc_nmhandle_t *handle) {
#if defined(__SANITIZE_ADDRESS__) || defined(__SANITIZE_THREAD__)
nmhandle_free(sock, handle);
#else
if (sock->active) {
if (sock->active &&
sock->inactive_handles_cur < sock->inactive_handles_max)
{
sock->inactive_handles_cur++;
ISC_LIST_APPEND(sock->inactive_handles, handle, inactive_link);
} else {
nmhandle_free(sock, handle);

View File

@@ -188,6 +188,7 @@ start_udp_child(isc_nm_t *mgr, isc_sockaddr_t *iface, isc_nmsocket_t *sock,
isc__nmsocket_init(csock, worker, isc_nm_udpsocket, iface, sock);
csock->recv_cb = sock->recv_cb;
csock->recv_cbarg = sock->recv_cbarg;
csock->inactive_handles_max = ISC_NM_NMHANDLES_MAX;
if (mgr->load_balance_sockets) {
csock->fd = isc__nm_udp_lb_socket(mgr,