Skip to content

Commit de6d941

Browse files
committed
Enhance the report statistics output
We now show rows for errors/no-data/success/total, instead of one row encompasing all.
1 parent 1697a5b commit de6d941

File tree

5 files changed

+87
-37
lines changed

5 files changed

+87
-37
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,17 @@ $ java -jar ./target/uberjar/app.jar -u https://manetu.example.com --insecure -q
9191
If successful, the test should display something similar to the following:
9292

9393
```shell
94-
2024-10-17T20:21:33.172Z INFO processing 10000 requests with concurrency 64
95-
2024-10-17T20:21:33.175Z INFO Loading bindings from: ./examples/by-email/bindings.csv
94+
2024-10-18T19:54:24.398Z INFO processing 10000 requests with concurrency 64
95+
2024-10-18T19:54:24.403Z INFO Loading bindings from: ./examples/by-email/bindings.csv
9696
10000/10000 100% [==================================================] ETA: 00:00
97-
|-----------+----------+------+-------+--------+--------+--------+----------------+--------|
98-
| Successes | Failures | Min | Q1 | Median | Q3 | Max | Total Duration | Rate |
99-
|-----------+----------+------+-------+--------+--------+--------+----------------+--------|
100-
| 10000.0 | 0.0 | 27.1 | 87.05 | 113.04 | 132.75 | 292.57 | 20517.48 | 487.39 |
101-
|-----------+----------+------+-------+--------+--------+--------+----------------+--------|
97+
|-------------+----------------+-------+--------+--------+--------+--------+--------+--------+--------|
98+
| Description | Count | Min | Mean | Stddev | P50 | P90 | P99 | Max | Rate |
99+
|-------------+----------------+-------+--------+--------+--------+--------+--------+--------+--------|
100+
| Errors | 0 (0.0%) | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
101+
| Not found | 0 (0.0%) | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
102+
| Successes | 10000 (100.0%) | 29.05 | 110.79 | 35.83 | 111.48 | 147.47 | 194.54 | 419.91 | 490.11 |
103+
| Total | 10000 (100.0%) | 29.05 | 110.79 | 35.83 | 111.48 | 147.47 | 194.54 | 419.91 | 490.11 |
104+
|-------------+----------------+-------+--------+--------+--------+--------+--------+--------+--------|
105+
Total Duration: 20403.423232msecs
102106
```
103107

project.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
[doric "0.9.0"]
2222
[org.clojure/data.csv "1.1.0"]
2323
[kixi/stats "0.5.6"]
24+
[redux "0.1.4"]
2425
[medley "1.4.0"]
2526
[district0x/graphql-query "1.0.6"]
2627
[http-kit "2.7.0-RC1"]

src/manetu/sparql_loadtest/core.clj

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
[taoensso.timbre :as log]
88
[clojure.core.async :refer [<! go go-loop] :as async]
99
[progrock.core :as pr]
10-
[kixi.stats.core :as kixi]
1110
[doric.core :refer [table]]
1211
[ring.util.codec :as ring.codec]
1312
[manetu.sparql-loadtest.binding-loader :as binding-loader]
14-
[manetu.sparql-loadtest.driver.api :as driver.api]))
13+
[manetu.sparql-loadtest.driver.api :as driver.api]
14+
[manetu.sparql-loadtest.stats :as stats]))
1515

1616
(defn execute-query
1717
[{:keys [driver] :as ctx} query bindings]
@@ -72,9 +72,11 @@
7272
(let [result (<! (async/transduce xform f (f) ch))]
7373
(resolve result)))))))
7474

75-
(defn compute-summary-stats
76-
[options n mux]
77-
(transduce-promise options n mux (map :duration) kixi/summary))
75+
(defn round2
76+
"Round a double to the given precision (number of significant digits)"
77+
[precision ^double d]
78+
(let [factor (Math/pow 10 precision)]
79+
(/ (Math/round (* d factor)) factor)))
7880

7981
(defn successful?
8082
[{:keys [success]}]
@@ -84,30 +86,42 @@
8486
[{:keys [success]}]
8587
(false? success))
8688

87-
(defn count-msgs
88-
[ctx n mux pred]
89-
(transduce-promise ctx n mux (filter pred) kixi/count))
89+
(defn rows-pred?
90+
[pred {{:keys [rows]} :result :as x}]
91+
(log/debug "x:" x)
92+
(pred rows))
93+
94+
(def zero-rows? (partial rows-pred? zero?))
95+
(def some-rows? (partial rows-pred? pos?))
96+
97+
(defn compute-summary-stats
98+
[options n mux pred]
99+
(-> (transduce-promise options n mux (comp (filter pred) (map :duration)) stats/summary)
100+
(p/then (fn [{:keys [dist] :as summary}]
101+
(-> summary
102+
(dissoc :dist)
103+
(merge dist)
104+
(as-> $ (m/map-vals #(round2 2 (or % 0)) $)))))))
90105

91106
(defn compute-stats
92107
[ctx n mux]
93-
(-> (p/all [(compute-summary-stats ctx n mux)
94-
(count-msgs ctx n mux successful?)
95-
(count-msgs ctx n mux failed?)])
96-
(p/then (fn [[summary s f]] (assoc summary :successes s :failures f)))))
97-
98-
(defn round2
99-
"Round a double to the given precision (number of significant digits)"
100-
[precision ^double d]
101-
(let [factor (Math/pow 10 precision)]
102-
(/ (Math/round (* d factor)) factor)))
108+
(-> (p/all (conj (map (partial compute-summary-stats ctx n mux)
109+
[failed?
110+
(every-pred successful? zero-rows?)
111+
(every-pred successful? some-rows?)
112+
identity])))
113+
(p/then (fn [[failed no-data data total :as summaries]]
114+
(log/trace "summaries:" summaries)
115+
(let [failures (get failed :count)]
116+
{:failures failures :summaries [(assoc failed :description "Errors")
117+
(assoc no-data :description "Not found")
118+
(assoc data :description "Successes")
119+
(assoc total :description "Total")]})))))
103120

104121
(defn render
105-
[ctx {:keys [failures] :as stats}]
106-
(let [stats (m/map-vals (partial round2 2) stats)]
107-
(println (table [:successes :failures :min :q1 :median :q3 :max :total-duration :rate] [stats]))
108-
(if (pos? failures)
109-
-1
110-
0)))
122+
[{:keys [nr] :as ctx} {:keys [total-duration summaries] :as stats}]
123+
(println (table [:description :count :min :mean :stddev :p50 :p90 :p99 :max :rate] (map #(update % :count (fn [count] (str (int count) " (" (* (/ count nr) 100) "%)"))) summaries)))
124+
(println "Total Duration:" (str total-duration "msecs")))
111125

112126
(defn process
113127
[{:keys [concurrency nr] :as ctx}]
@@ -119,8 +133,17 @@
119133
(show-progress ctx nr mux)
120134
(compute-stats ctx nr mux)])
121135
(p/then
122-
(fn [[start _ _ {:keys [successes] :as stats}]]
136+
(fn [[start _ _ stats]]
123137
(let [end (t/now)
124138
d (t/duration end start)]
125-
(assoc stats :total-duration d :rate (* (/ successes d) 1000)))))
126-
(p/then (partial render ctx)))))
139+
(-> stats
140+
(update :summaries (fn [summaries]
141+
(map (fn [{:keys [count] :as summary}]
142+
(assoc summary :rate (round2 2 (* (/ count d) 1000))))
143+
summaries)))
144+
(assoc :total-duration d)))))
145+
(p/then (fn [{:keys [failures] :as stats}]
146+
(render ctx stats)
147+
(if (pos? failures)
148+
-1
149+
0))))))

src/manetu/sparql_loadtest/driver/drivers/gql.clj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@
4242
:encoding :URL
4343
:bindings (->bindings bindings)}
4444
[:name :value]]]})})
45-
(p/then (fn [r]
46-
(log/trace "result:" r)
47-
{}))))
45+
(p/then (fn [{{:strs [data errors]} :body :as r}]
46+
(log/trace "result:" r "data:" data "errors:" errors)
47+
(if (some? errors)
48+
(p/rejected (ex-info "graphql error" r))
49+
(let [rows (-> data (get "sparql_query") count)]
50+
(log/trace "rows:" rows)
51+
{:rows rows}))))))
4852

4953
(defrecord GraphQLDriver [ctx]
5054
api/LoadDriver

src/manetu/sparql_loadtest/stats.clj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
;; Copyright © Manetu, Inc. All rights reserved
2+
3+
(ns manetu.sparql-loadtest.stats
4+
(:require [kixi.stats.core :refer [count mean standard-deviation histogram post-complete]]
5+
[kixi.stats.distribution :refer [minimum maximum quantile]]
6+
[redux.core :refer [fuse]]))
7+
8+
(def summary (fuse {:count count
9+
:mean mean
10+
:stddev standard-deviation
11+
:dist (post-complete histogram
12+
(fn [hist]
13+
{:min (minimum hist)
14+
:p50 (quantile hist 0.50)
15+
:p90 (quantile hist 0.90)
16+
:p95 (quantile hist 0.95)
17+
:p99 (quantile hist 0.99)
18+
:max (maximum hist)}))}))

0 commit comments

Comments
 (0)