-
Notifications
You must be signed in to change notification settings - Fork 14
/
bench.lisp
143 lines (129 loc) · 5.34 KB
/
bench.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
;;(push #P"~/Development/MySources/sento/" asdf:*central-registry*)
(asdf:load-system "sento")
(log:config :warn)
(defparameter *starttime* 0)
(defparameter *endtime* 0)
(defparameter *withreply-p* nil)
(defparameter *system* nil)
(defparameter *actor* nil)
(defparameter *counter* 0)
(defparameter +threads+ 8)
(defparameter *per-thread* nil)
(defun max-loop () (* *per-thread* +threads+))
(defun runner-bt (&optional (withreply-p nil) (asyncask nil) (queue-size 0))
(declare (ignore queue-size))
;; dispatchers used for the async-ask
(setf *per-thread* 125000)
(setf *system* (asys:make-actor-system '(:dispatchers (:shared (:workers 8)))))
(setf *actor* (ac:actor-of *system*
:receive (lambda (msg)
(declare (ignore msg))
(incf *counter*))
:dispatcher :pinned))
(setf *withreply-p* withreply-p)
(setf *counter* 0)
(setf *starttime* (get-universal-time))
(format t "Times: ~a~%" (max-loop))
(time
(progn
(map nil #'bt2:join-thread
(mapcar (lambda (x)
(bt2:make-thread
(lambda ()
(dotimes (n *per-thread*)
(if withreply-p
(if asyncask
(act:ask *actor* :foo)
(act:ask-s *actor* :foo))
(act:tell *actor* :foo))))
:name x))
(mapcar (lambda (n) (format nil "thread-~a" n))
(loop :for n :from 1 :to +threads+ :collect n))))
(miscutils:assert-cond (lambda () (= *counter* (max-loop))) 20)))
(setf *endtime* (get-universal-time))
(format t "Counter: ~a~%" *counter*)
(format t "Elapsed: ~a~%" (- *endtime* *starttime*))
(print *system*)
(ac:shutdown *system*))
(defun runner-dp (&optional (withreply-p nil) (asyncask nil) (queue-size 0))
(declare (ignore queue-size))
(setf *per-thread* 125000)
(setf *system* (asys:make-actor-system '(:dispatchers (:shared (:workers 8)))))
(setf *actor* (ac:actor-of *system*
:receive (lambda (msg)
(declare (ignore msg))
(incf *counter*))
:dispatcher :shared))
;;(print *actor*)
(setf *withreply-p* withreply-p)
(setf *counter* 0)
(setf *starttime* (get-universal-time))
(format t "Times: ~a~%" (max-loop))
(time
(progn
(map nil #'bt2:join-thread
(mapcar (lambda (x)
(bt2:make-thread
(lambda ()
(dotimes (n *per-thread*)
(if withreply-p
(if asyncask
(act:ask *actor* :foo)
(act:ask-s *actor* :foo))
(act:tell *actor* :foo))))
:name x))
(mapcar (lambda (n) (format nil "thread-~a" n))
(loop for n from 1 to +threads+ collect n))))
(miscutils:assert-cond (lambda () (= *counter* (max-loop))) 120)))
(setf *endtime* (get-universal-time))
(format t "Counter: ~a~%" *counter*)
(format t "Elapsed: ~a~%" (- *endtime* *starttime*))
;;(print *system*)
(ac:shutdown *system*))
;; (defun runner-lp ()
;; (setf *msgbox* (make-instance 'sento.messageb::message-box-lsr))
;; (setf lparallel:*kernel* (lparallel:make-kernel +threads+))
;; (setf *counter* 0)
;; (unwind-protect
;; (time
;; (let ((chan (lparallel:make-channel)))
;; (dotimes (n (max-loop))
;; (lparallel:submit-task chan #'msg-submit))
;; (dotimes (n (max-loop))
;; (lparallel:receive-result chan))))
;; (format t "Counter: ~a~%" *counter*)
;; (lparallel:end-kernel)
;; (sento.messageb::stop *msgbox*)))
;; (defun runner-lp2 ()
;; (setf *msgbox* (make-instance 'sento.messageb::message-box-lsr))
;; (setf lparallel:*kernel* (lparallel:make-kernel +threads+))
;; (setf *counter* 0)
;; (unwind-protect
;; (time
;; (progn
;; (map nil #'lparallel:force
;; (mapcar (lambda (x)
;; (lparallel:future
;; (dotimes (n *per-thread*)
;; (msg-submit))))
;; (mapcar (lambda (n) (format nil "thread-~a" n))
;; (loop for n from 1 to +threads+ collect n))))
;; (format t "Counter: ~a~%" *counter*)
;; (assert-cond (lambda () (= *counter* (max-loop))) 5)))
;; (format t "Counter: ~a~%" *counter*)
;; (lparallel:end-kernel)
;; (sento.messageb::stop *msgbox*)))
;; (defun runner-lp3 ()
;; (setf *msgbox* (make-instance 'sento.messageb::message-box-lsr))
;; (setf lparallel:*kernel* (lparallel:make-kernel +threads+))
;; (setf *counter* 0)
;; (unwind-protect
;; (time
;; (lparallel:pmap nil (lambda (per-thread)
;; (dotimes (n per-thread)
;; (msg-submit)))
;; :parts 1
;; (loop repeat +threads+ collect *per-thread*)))
;; (format t "Counter: ~a~%" *counter*)
;; (lparallel:end-kernel)
;; (sento.messageb::stop *msgbox*)))