@@ -14,17 +14,18 @@ import (
1414)
1515
1616var (
17- redisAddr string
18- redisPass string
19- redisDB int
20- numClients int
21- numKeys int
22- keyPrefix string
23- ttl time.Duration
24- testDuration time.Duration
25- setRatio float64
26- getRatio float64
27- delRatio float64
17+ redisAddr string
18+ redisPass string
19+ redisDB int
20+ numClients int
21+ numKeys int
22+ keyPrefix string
23+ ttl time.Duration
24+ testDuration time.Duration
25+ setRatio float64
26+ getRatio float64
27+ delRatio float64
28+ totalSetData , totalGetData int64
2829)
2930
3031type operationStats struct {
@@ -99,7 +100,8 @@ func main() {
99100 for i := 0 ; i < numClients ; i ++ {
100101 wg .Add (1 )
101102 go clientWorker (ctx , rdb , keys , ttl , setRatio , getRatio , delRatio , progress [i ],
102- & totalSet , & totalGet , & totalDel , & lock , stop , & setStats , & getStats , & delStats , & wg )
103+ & totalSet , & totalGet , & totalDel , & lock , stop , & setStats , & getStats , & delStats , & totalSetData , & totalGetData , & wg )
104+
103105 }
104106
105107 // Start statistics reporter
@@ -121,6 +123,8 @@ func main() {
121123 fmt .Printf ("SET operations: %d\n " , totalSet )
122124 fmt .Printf ("GET operations: %d\n " , totalGet )
123125 fmt .Printf ("DEL operations: %d\n " , totalDel )
126+ fmt .Printf ("Total data sent during SET operations: %.2f MB\n " , float64 (totalSetData )/ (1024 * 1024 ))
127+ fmt .Printf ("Total data retrieved during GET operations: %.2f MB\n " , float64 (totalGetData )/ (1024 * 1024 ))
124128 fmt .Printf ("Average SET ops/sec: %.2f\n " , float64 (totalSet )/ testDuration .Seconds ())
125129 fmt .Printf ("Average GET ops/sec: %.2f\n " , float64 (totalGet )/ testDuration .Seconds ())
126130 fmt .Printf ("Average DEL ops/sec: %.2f\n " , float64 (totalDel )/ testDuration .Seconds ())
@@ -159,6 +163,7 @@ func clientWorker(
159163 lock * sync.Mutex ,
160164 stop <- chan struct {},
161165 setStats , getStats , delStats * operationStats ,
166+ totalSetData , totalGetData * int64 , // New parameters for data size
162167 wg * sync.WaitGroup ,
163168) {
164169 defer wg .Done ()
@@ -174,25 +179,28 @@ func clientWorker(
174179
175180 if op < setRatio {
176181 // SET operation
177- value := randomString (100 )
182+ value := randomString (100 ) // Assuming 100 bytes per value
178183 start := time .Now ()
179184 if err := rdb .Set (ctx , key , value , ttl ).Err (); err == nil {
180185 duration := time .Since (start ).Seconds () * 1000
181186 updateStats (setStats , duration )
182187 lock .Lock ()
183188 progress ["set" ]++
184189 * totalSet ++
190+ * totalSetData += int64 (len (value )) + int64 (len (key )) // Data size includes key and value
185191 lock .Unlock ()
186192 }
187193 } else if op < setRatio + getRatio {
188194 // GET operation
189195 start := time .Now ()
190- if _ , err := rdb .Get (ctx , key ).Result (); err == nil || err == redis .Nil {
196+ result , err := rdb .Get (ctx , key ).Result ()
197+ if err == nil || err == redis .Nil {
191198 duration := time .Since (start ).Seconds () * 1000
192199 updateStats (getStats , duration )
193200 lock .Lock ()
194201 progress ["get" ]++
195202 * totalGet ++
203+ * totalGetData += int64 (len (result )) + int64 (len (key )) // Data size includes key and value
196204 lock .Unlock ()
197205 }
198206 } else {
0 commit comments