changelog shortlog graph tags branches changeset file revisions annotate raw help

Mercurial > demo / examples/db/mini-redis.lisp

revision 38: 8259376eee11
parent 37: c6d0a37a046a
child 39: 1ef551e24009
     1.1--- a/examples/db/mini-redis.lisp	Sun Dec 24 19:24:39 2023 -0500
     1.2+++ b/examples/db/mini-redis.lisp	Fri Dec 29 00:45:44 2023 -0500
     1.3@@ -2,14 +2,26 @@
     1.4 
     1.5 ;; based on https://github.com/no-defun-allowed/concurrent-hash-tables/blob/master/Examples/phony-redis.lisp
     1.6 
     1.7+;; if the heap gets exhausted you probably want to trying increasing
     1.8+;; the dynamic-space-size at runtime.
     1.9+
    1.10 ;;; Code:
    1.11-(require 'sb-concurrency)
    1.12 (defpackage :examples/mini-redis
    1.13   (:use :cl :std :net :obj :cli :sb-concurrency :sb-thread)
    1.14-  (:export))
    1.15+  (:export :main))
    1.16 
    1.17 (in-package :examples/mini-redis)
    1.18 
    1.19+(defparameter *worker-count* 4)
    1.20+(defparameter *writer-proportion* 0.5)
    1.21+(defvar *keys*
    1.22+  (loop for n below 130 by 2
    1.23+        collect (format nil "~r" n)))
    1.24+(defvar *other-keys*
    1.25+  (loop for n from 1 below 128 by 2
    1.26+        collect (format nil "~r" n)))
    1.27+(defvar *ops* 400000)
    1.28+
    1.29 (defun make-server ()
    1.30   (make-castable :test #'equal))
    1.31 
    1.32@@ -26,12 +38,12 @@
    1.33              (:quit (return))
    1.34              (:get 
    1.35               (multiple-value-bind (val p)
    1.36-                  (obj/hash:cgethash (cdr msg) server)
    1.37+                  (getchash (cdr msg) server)
    1.38                 (if p
    1.39                     (send-message rx `(:found ,val))
    1.40                     (send-message rx `(:not-found)))))
    1.41              (:put
    1.42-              (setf (cgethash (cadr msg) server)
    1.43+              (setf (getchash (cadr msg) server)
    1.44                     (copy-seq (caddr msg)))
    1.45               (send-message rx '(:ok)))
    1.46              (t (return))))))
    1.47@@ -87,16 +99,6 @@
    1.48         (setf position (mod (1+ position) 100))))
    1.49     (close-conn conn)))
    1.50 
    1.51-(defparameter *worker-count* 8)
    1.52-(defparameter *writer-proportion* 0.5)
    1.53-(defvar *keys*
    1.54-  (loop for n below 130 by 2
    1.55-        collect (format nil "~r" n)))
    1.56-(defvar *other-keys*
    1.57-  (loop for n from 1 below 128 by 2
    1.58-        collect (format nil "~r" n)))
    1.59-(defvar *ops* 10000000)
    1.60-
    1.61 (defun run (&optional (worker-count *worker-count*)
    1.62               (writer-proportion *writer-proportion*)
    1.63               (keys *keys*))
    1.64@@ -120,7 +122,8 @@
    1.65                              internal-time-units-per-second)))
    1.66              (throughput (/ (* *ops* worker-count) time)))
    1.67         (format t "~&~20@a: ~$ seconds (~d transactions/second)"
    1.68-                "mini-redis" time (round throughput))))))
    1.69+                "mini-redis" time (round throughput))))
    1.70+    server))
    1.71 
    1.72 (defmain ()
    1.73-  (run 4 1.0 *keys*))
    1.74+  (run))