commit b2abf1f22277fcbacb784c97e1b1e6e922ca8a35
parent 0745c973b5032194c33ef481a302eb1bcff8c11d
Author: Renev Pavel <an2qzavok@gmail.com>
Date: Fri, 10 Feb 2023 13:11:50 +0000
src/bench: some stress tests
Diffstat:
3 files changed, 98 insertions(+), 1 deletion(-)
diff --git a/src/bench/mkfile b/src/bench/mkfile
@@ -1,5 +1,5 @@
</$objtype/mkfile
BIN=.
-TARG=reader writer
+TARG=reader writer ramstress wdbstress
</sys/src/cmd/mkmany
diff --git a/src/bench/ramstress.c b/src/bench/ramstress.c
@@ -0,0 +1,50 @@
+/*
+ Create n files, then read n files in /tmp;
+ measure time.
+*/
+
+#include <u.h>
+#include <libc.h>
+
+char buf[256];
+
+void
+create1(char *path)
+{
+ int n, fd = create(path, OWRITE, 0666);
+ if (fd < 0) sysfatal("%r");
+ n = snprint(buf, 256, "uhehe guhehe\n");
+ write(fd, buf, n);
+ close(fd);
+}
+
+void
+read1(char *path)
+{
+ int fd = open(path, OREAD);
+ if (fd < 0) sysfatal("%r");
+ read(fd, buf, 256);
+ close(fd);
+}
+
+void
+main(int argc, char **argv)
+{
+ long t[2], b[4];
+ if (argc < 2) exits("no arg");
+ long i, l = strtol(argv[1], nil, 10);
+ t[0] = times(b);
+ for (i = 0; i < l; i++) {
+ snprint(buf, 256, "/tmp/%ld", i);
+ create1(buf);
+ }
+ t[1] = times(b);
+ print("create: %ld ms\n", t[1] - t[0]);
+ t[0] = times(b);
+ for (i = 0; i < l; i++) {
+ snprint(buf, 256, "/tmp/%ld", i);
+ read1(buf);
+ }
+ t[1] = times(b);
+ print("read: %ld ms\n", t[1] - t[0]);
+}
diff --git a/src/bench/wdbstress.c b/src/bench/wdbstress.c
@@ -0,0 +1,47 @@
+/*
+ Create n files, then read n entries in wdb keyval store;
+ measure time.
+*/
+
+#include <u.h>
+#include <libc.h>
+
+int fd;
+char buf[256];
+
+void
+create1(char *key)
+{
+ fprint(fd, "store %s %s", key, "uhehe guhehe\n");
+ read(fd, buf, 256);
+}
+
+void
+read1(char *key)
+{
+ fprint(fd, "fetch %s %s", key, "uhehe guhehe\n");
+ read(fd, buf, 256);
+}
+
+void
+main(int argc, char **argv)
+{
+ long t[2], b[4];
+ if (argc < 2) exits("no arg");
+ long i, l = strtol(argv[1], nil, 10);
+ fd = open("/srv/wdb", ORDWR);
+ t[0] = times(b);
+ for (i = 0; i < l; i++) {
+ snprint(buf, 256, "%ld", i);
+ create1(buf);
+ }
+ t[1] = times(b);
+ print("create: %ld ms\n", t[1] - t[0]);
+ t[0] = times(b);
+ for (i = 0; i < l; i++) {
+ snprint(buf, 256, "%ld", i);
+ read1(buf);
+ }
+ t[1] = times(b);
+ print("read: %ld ms\n", t[1] - t[0]);
+}