Skip to content

Commit 5c296a2

Browse files
committed
bench: skip oversized pool cases based on fd budget
1 parent 852e117 commit 5c296a2

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

‎bench/bench_checkout.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
static int
1212
run_case(uint32_t pool_size, uint32_t iterations)
1313
{
14+
uint32_t fd_budget;
1415
pid_t server_pid = -1;
1516
uint16_t port = 0;
1617
int event_fd = -1;
@@ -23,6 +24,14 @@ run_case(uint32_t pool_size, uint32_t iterations)
2324
int err = 0;
2425
int rc = 0;
2526

27+
fd_budget = bench_fd_budget();
28+
if (pool_size > fd_budget) {
29+
printf("checkout with immediate connection (pool size %u): "
30+
"skipped (fd budget %u)\n",
31+
pool_size, fd_budget);
32+
return 0;
33+
}
34+
2635
if (bench_start_server(&server_pid, &port) != BRAID_OK)
2736
return 1;
2837

‎bench/bench_common.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <stdio.h>
88
#include <stdlib.h>
99
#include <string.h>
10+
#include <sys/resource.h>
1011
#include <sys/socket.h>
1112
#include <sys/types.h>
1213
#include <sys/utsname.h>
@@ -285,6 +286,27 @@ bench_pool_idle_count(braid_pool_t *pool)
285286
return count;
286287
}
287288

289+
uint32_t
290+
bench_fd_budget(void)
291+
{
292+
struct rlimit lim;
293+
const rlim_t reserve = (rlim_t)64;
294+
295+
if (getrlimit(RLIMIT_NOFILE, &lim) != 0)
296+
return UINT32_MAX;
297+
298+
if (lim.rlim_cur == RLIM_INFINITY)
299+
return UINT32_MAX;
300+
301+
if (lim.rlim_cur <= reserve)
302+
return 0;
303+
304+
if (lim.rlim_cur - reserve > (rlim_t)UINT32_MAX)
305+
return UINT32_MAX;
306+
307+
return (uint32_t)(lim.rlim_cur - reserve);
308+
}
309+
288310
int
289311
bench_warm_pool(braid_pool_t *pool, int event_fd, uint32_t want_idle,
290312
int max_steps)

‎bench/bench_common.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ int bench_start_server(pid_t *pid_out, uint16_t *port_out);
2424
void bench_stop_server(pid_t pid);
2525
int bench_event_loop_step(braid_pool_t *pool, int event_fd, int max_wait_ms);
2626
uint32_t bench_pool_idle_count(braid_pool_t *pool);
27+
uint32_t bench_fd_budget(void);
2728
int bench_warm_pool(braid_pool_t *pool, int event_fd, uint32_t want_idle,
2829
int max_steps);
2930
void bench_print_hw_context(const char *name);

‎bench/bench_pool_scale.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
static int
1212
run_case(uint32_t pool_size, uint32_t operations)
1313
{
14+
uint32_t fd_budget;
1415
pid_t server_pid = -1;
1516
uint16_t port = 0;
1617
int event_fd = -1;
@@ -23,6 +24,14 @@ run_case(uint32_t pool_size, uint32_t operations)
2324
int err = 0;
2425
int rc = 0;
2526

27+
fd_budget = bench_fd_budget();
28+
if (pool_size > fd_budget) {
29+
printf("pool scale (max_connections=%u): "
30+
"skipped (fd budget %u)\n",
31+
pool_size, fd_budget);
32+
return 0;
33+
}
34+
2635
if (bench_start_server(&server_pid, &port) != BRAID_OK)
2736
return 1;
2837

0 commit comments

Comments
 (0)