blob: 2410032e63a25aec98da3d048f3079863ab05ac7 (
plain)
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
|
(ns dumpfm.load-test
(:import org.postgresql.ds.PGPoolingDataSource)
(:use clojure.contrib.json.read
clojure.contrib.json.write
clojure.contrib.seq-utils
clojure.contrib.sql
dumpfm.millstone))
(let [db-host "localhost"
db-name "dumpfm"
db-user "postgres"
db-pass "root"]
(def *db* {:datasource (doto (new PGPoolingDataSource)
(.setServerName db-host)
(.setDatabaseName db-name)
(.setUser db-user)
(.setPassword db-pass)
(.setMaxConnections 3))}))
(def userlist-query "
select u.nick, u.hash
from users u, messages m
where u.user_id = m.user_id
and u.user_id not in
(select user_id from mutes where (set_on + duration < now()))
group by u.nick, u.hash
having count(*) > 50
order by count(*) desc
")
(print "Fetching userlist: ")
(def userlist (time
(with-connection *db*
(with-query-results rs [userlist-query]
(doall rs)))))
(def sample-messages-query "
select content
from messages
order by random()
limit 100
")
(print "Fetching messages: ")
(def message-contents (time
(with-connection *db*
(with-query-results rs [sample-messages-query]
(doall (map :content rs))))))
(defn login-client []
(let [user-info (rand-elt userlist)
params (select-keys user-info [:nick :hash])]
(do-setup-request! "/login"
:params params
:method "GET")))
(defn chat []
(do-request! "/test/chat"))
(defn refresh []
(let [params {:since (- (System/currentTimeMillis) 2000)
:room "test"}]
(do-request! "/refresh"
:params params
:method "GET")
(Thread/sleep 1000)))
(defn post-msg []
(let [params {:content (rand-elt message-contents)
:room "test"}]
(do-request! "/msg"
:params params
:method "POST")))
(def test-spec {:server "http://localhost:8080"
:clients 200
:requests 10000
:max-latency 1000
:setup-func login-client
:funcs [[55 refresh]
[3 chat]
[5 post-msg]]
:frequency 1
})
(grind! test-spec)
(System/exit 0)
|