This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository terminology.
View the commit online.
commit eb43804c05307ab8cb2e9db022b8001710396314
Author: [email protected] <[email protected]>
AuthorDate: Thu Sep 24 22:16:31 2026 -0600
tybenchd: benchmark tymuxd throughput
tybenchd starts a tymuxd whose shell prints the numbers from 1 to N and
measures the time until the shell exits. That covers what the daemon
does for every byte: parsing it, publishing the screen and notifying a
client. With -l the shell prints one line per write, like an
interactive program, instead of the large writes of seq(1).
It is built with -Dbenchmarks=true and run with:
meson test -C build --benchmark tymuxd-throughput -v
---
DESIGN.md | 1 +
meson_options.txt | 2 +-
src/bin/meson.build | 7 ++
src/bin/tybenchd.c | 246 ++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/meson.build | 7 ++
5 files changed, 262 insertions(+), 1 deletion(-)
diff --git a/DESIGN.md b/DESIGN.md
index 90a71c35..5075514b 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -39,6 +39,7 @@ A simple documentation to navigate through the C files:
* `src/bin/termptystatus.c`: program status escape codes (OSC 7501)
* `src/bin/termsrv.c`: the tymux wire protocol shared by `tymuxd` and `tymux`: messages, screen shared memory, daemon spawning
* `src/bin/tyalpha.c`: the `tyalpha` tool
+* `src/bin/tybenchd.c`: the `tybenchd` tool, benchmarks the throughput of `tymuxd`
* `src/bin/tybg.c`: the `tybg` tool
* `src/bin/tycat.c`: the `tycat` tool
* `src/bin/tyls.c`: the `tyls` tool
diff --git a/meson_options.txt b/meson_options.txt
index 57917b70..5946e4cc 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -15,7 +15,7 @@ option('tests',
option('benchmarks',
type: 'boolean',
value: false,
- description: 'Enable generating tybench, used to benchmark the pty intake path. (default=false)')
+ description: 'Enable generating tybench and tybenchd, used to benchmark the pty intake path and tymuxd. (default=false)')
option('nls',
type: 'boolean',
value: true,
diff --git a/src/bin/meson.build b/src/bin/meson.build
index 93c9763a..8295720c 100644
--- a/src/bin/meson.build
+++ b/src/bin/meson.build
@@ -312,4 +312,11 @@ if benchmarks
include_directories: config_dir,
c_args: ['-DBINARY_TYFUZZ=1', '-DBINARY_TYBENCH=1'],
dependencies: terminology_dependencies)
+ if host_os == 'linux'
+ tybenchd = executable('tybenchd',
+ ['tybenchd.c', 'termsrv.c', 'termsrv.h'],
+ install: false,
+ include_directories: config_dir,
+ dependencies: [eina_dep, ecore_dep])
+ endif
endif
diff --git a/src/bin/tybenchd.c b/src/bin/tybenchd.c
new file mode 100644
index 00000000..b084ea27
--- /dev/null
+++ b/src/bin/tybenchd.c
@@ -0,0 +1,246 @@
+/* Throughput benchmark for tymuxd.
+ *
+ * Starts a tymuxd, attaches to it and has its shell print the numbers from 1
+ * to LINES, then measures the time until the shell exits. This covers what
+ * the daemon does for every byte the shell prints: parsing it, publishing
+ * the screen and notifying the client, which only counts the notifications.
+ *
+ * By default the numbers come from seq(1), in large writes. With -l, the
+ * shell prints them one write per line, like an interactive program would.
+ */
+#include "private.h"
+#include <errno.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+#include <Eina.h>
+#include <Ecore.h>
+#include "termsrv.h"
+
+#define DEFAULT_ITERATIONS 5
+#define DEFAULT_LINES 100000
+
+typedef struct
+{
+ double seconds;
+ long notifies;
+} Run;
+
+static double
+_now(void)
+{
+ struct timespec ts;
+
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return (double)ts.tv_sec + (double)ts.tv_nsec / 1e9;
+}
+
+/* Watches the daemon's socket for the run in progress: NOTIFY messages are
+ * counted, EXIT ends the run successfully, and 60s without any message ends
+ * it as a failure (a daemon that hung would otherwise wait forever). */
+typedef struct
+{
+ Run *run;
+ int sock;
+ TermSrvReader reader;
+ Ecore_Timer *timeout;
+ Eina_Bool ok;
+} Bench_Watch;
+
+static Eina_Bool
+_cb_timeout(void *data)
+{
+ Bench_Watch *watch = data;
+
+ fprintf(stderr, "tybenchd: no answer from tymuxd\n");
+ watch->timeout = NULL;
+ ecore_main_loop_quit();
+ return ECORE_CALLBACK_CANCEL;
+}
+
+static Eina_Bool
+_cb_fd(void *data, Ecore_Fd_Handler *fdh __attribute__((unused)))
+{
+ Bench_Watch *watch = data;
+ void *payload;
+ uint32_t size;
+ int type = 0;
+
+ ecore_timer_reset(watch->timeout);
+ if (termsrv_reader_fill(&watch->reader, watch->sock) < 0)
+ {
+ ecore_main_loop_quit();
+ return ECORE_CALLBACK_CANCEL;
+ }
+ while ((type = termsrv_reader_next(&watch->reader, &payload, &size)) > 0)
+ {
+ free(payload);
+ if (type == TSRV_MSG_NOTIFY)
+ watch->run->notifies++;
+ else if (type == TSRV_MSG_EXIT)
+ {
+ watch->ok = EINA_TRUE;
+ ecore_main_loop_quit();
+ return ECORE_CALLBACK_RENEW;
+ }
+ }
+ if (type < 0 || watch->reader.eof)
+ ecore_main_loop_quit();
+ return ECORE_CALLBACK_RENEW;
+}
+
+static int
+_run(const char *name, const char *cmd, Run *run)
+{
+ TermSrvMsgAttached attached;
+ Bench_Watch watch = { .run = run, .ok = EINA_FALSE };
+ Ecore_Fd_Handler *fdh;
+ int sock, shm_fd;
+ double start;
+ int ret = -1;
+
+ if (termsrv_daemon_spawn(name) < 0)
+ {
+ fprintf(stderr, "tybenchd: could not start tymuxd\n");
+ return -1;
+ }
+ sock = termsrv_connect(name);
+ if (sock < 0)
+ return -1;
+ if (termsrv_msg_send(sock, TSRV_MSG_ATTACH, NULL, 0) < 0 ||
+ termsrv_recv_attached(sock, &shm_fd, &attached) < 0)
+ goto end;
+ close(shm_fd);
+
+ run->notifies = 0;
+ start = _now();
+ if (termsrv_msg_send(sock, TSRV_MSG_INPUT, cmd, strlen(cmd)) < 0)
+ goto end;
+
+ watch.sock = sock;
+ watch.timeout = ecore_timer_add(60.0, _cb_timeout, &watch);
+ fdh = ecore_main_fd_handler_add(sock, ECORE_FD_READ | ECORE_FD_ERROR,
+ _cb_fd, &watch, NULL, NULL);
+ ecore_main_loop_begin();
+ ecore_main_fd_handler_del(fdh);
+ if (watch.timeout)
+ ecore_timer_del(watch.timeout);
+ if (!watch.ok)
+ goto end;
+
+ run->seconds = _now() - start;
+ ret = 0;
+
+end:
+ termsrv_reader_clear(&watch.reader);
+ close(sock);
+ return ret;
+}
+
+static int
+_cmp_run(const void *a, const void *b)
+{
+ double sa = ((const Run *)a)->seconds, sb = ((const Run *)b)->seconds;
+
+ return (sa > sb) - (sa < sb);
+}
+
+static int
+_main(int argc, char **argv)
+{
+ long iterations = DEFAULT_ITERATIONS, lines = DEFAULT_LINES;
+ long bytes = 0, n, i;
+ char name[TERMSRV_NAME_MAX + 1];
+ char cmd[128];
+ bool line_by_line = false;
+ Run *runs;
+ int opt;
+
+ while ((opt = getopt(argc, argv, "i:lh")) != -1)
+ {
+ switch (opt)
+ {
+ case 'i':
+ iterations = strtol(optarg, NULL, 10);
+ break;
+ case 'l':
+ line_by_line = true;
+ break;
+ default:
+ fprintf(stderr, "Usage: %s [-i ITERATIONS] [-l] [LINES]\n",
+ argv[0]);
+ return opt == 'h' ? 0 : 1;
+ }
+ }
+ if (optind < argc)
+ lines = strtol(argv[optind], NULL, 10);
+ if (iterations <= 0 || lines <= 0)
+ {
+ fprintf(stderr, "tybenchd: invalid arguments\n");
+ return 1;
+ }
+ runs = calloc(iterations, sizeof(Run));
+ if (!runs)
+ return 1;
+
+ signal(SIGPIPE, SIG_IGN);
+ /* a plain shell: the startup files of the user's shell are not what is
+ * measured */
+ setenv("SHELL", "/bin/sh", 1);
+ if (termsrv_ensure_tymux_dir() < 0)
+ {
+ perror("tybenchd");
+ return 1;
+ }
+
+ if (line_by_line)
+ snprintf(cmd, sizeof(cmd),
+ "i=1; while [ $i -le %ld ]; do echo $i; i=$((i+1)); done; exit\n",
+ lines);
+ else
+ snprintf(cmd, sizeof(cmd), "seq 1 %ld; exit\n", lines);
+ for (n = 1; n <= lines; n *= 10)
+ bytes += (lines - n + 1);
+ bytes += lines;
+
+ for (i = 0; i < iterations; i++)
+ {
+ snprintf(name, sizeof(name), "tybenchd-%d-%ld", (int)getpid(), i);
+ if (_run(name, cmd, &runs[i]) < 0)
+ {
+ free(runs);
+ return 1;
+ }
+ printf("run %ld: %.3f s, %.1f MB/s, %ld notifications\n", i + 1,
+ runs[i].seconds, bytes / runs[i].seconds / 1e6,
+ runs[i].notifies);
+ }
+ qsort(runs, iterations, sizeof(Run), _cmp_run);
+ printf("%s1 to %ld (%ld bytes): median %.3f s, %.1f MB/s,"
+ " %ld notifications\n", line_by_line ? "line by line, " : "",
+ lines, bytes,
+ runs[iterations / 2].seconds,
+ bytes / runs[iterations / 2].seconds / 1e6,
+ runs[iterations / 2].notifies);
+ free(runs);
+ return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+ int ret;
+
+ eina_init();
+ /* no use for power/timezone/D-Bus system monitoring in a benchmark */
+ ecore_app_no_system_modules();
+ ecore_init();
+ ret = _main(argc, argv);
+ ecore_shutdown();
+ eina_shutdown();
+ return ret;
+}
diff --git a/tests/meson.build b/tests/meson.build
index 354d7cc9..2ae17348 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -148,4 +148,11 @@ if benchmarks
bench_corpus_dir / 'strings'],
depends: bench_corpus,
timeout: 600)
+ if host_os == 'linux'
+ benchmark('tymuxd-throughput',
+ tybenchd,
+ args: ['-i', '5', '1000000'],
+ depends: tymuxd,
+ timeout: 600)
+ endif
endif
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.