diff options
| author | Scott Ostler <sostler@deathmachine.local> | 2009-11-15 00:53:54 -0500 |
|---|---|---|
| committer | Scott Ostler <sostler@deathmachine.local> | 2009-11-15 00:53:54 -0500 |
| commit | 6a0934931cbccbb5a4b26b1ca470d93236f47ea3 (patch) | |
| tree | 05ee5e00afad153616c5817fbabaedd1c700a970 | |
| parent | df5aa85c037ebd576a87f6466862ebf002308a4a (diff) | |
Changed benchmark test
| -rwxr-xr-x | src/benchmark.clj | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/benchmark.clj b/src/benchmark.clj index 5573e56..3adf843 100755 --- a/src/benchmark.clj +++ b/src/benchmark.clj @@ -31,6 +31,10 @@ (nth (seq s) (. random nextInt (count s)))) +(defn refresh [] + (dosync + {"users" (keys @users) "messages" @messages})) + (defn add-user [] (dosync (if (= (count @users) room-limit) @@ -38,7 +42,8 @@ (alter users dissoc loser))) (let [nick (random-string 10)] (alter users assoc nick (struct user-struct nick (System/currentTimeMillis))) - (json-str {"users" (keys @users) "messages" (reverse @messages)})))) + {"users" (keys @users) "messages" (reverse @messages)}))) + (defn post-message [] (dosync @@ -47,19 +52,23 @@ (ref-set messages (conj (take (- 100 1) @messages) (struct message-struct nick msg (System/currentTimeMillis)))) (alter users assoc-in [nick :last-seen] (System/currentTimeMillis)) - (json-str "OK")))) + "OK"))) + (defn do-bench [] (let [r (.nextDouble random)] - (if (or (= 0 (count @users)) (< r 0.1)) - (add-user) - (post-message)))) + (cond (< r 0.8) (json-str (refresh)) + (< r 0.9) (json-str (add-user)) + (< r 1) (json-str (post-message))))) +(defn hello-world [] + "hello world!") (defroutes benchmark + (GET "/hello" (hello-world)) (ANY "*" (do-bench))) - +(add-user) (run-server {:port 8080} "/*" (servlet benchmark))
\ No newline at end of file |
