@@ -48,22 +48,30 @@ var (
48
48
func printStats () {
49
49
if printStatsV {
50
50
start := time .Now ()
51
- ticker := time .NewTicker (2 * time .Second )
51
+ ticker := time .NewTicker (1 * time .Second )
52
52
go func () {
53
53
for {
54
54
select {
55
55
case _ = <- ticker .C :
56
- v := time .Now ().Sub (start ).Seconds ()
57
- PMessagesPerSecond := int64 (float64 (atomic .LoadInt32 (& publisherMessageCount )) / v )
58
- CMessagesPerSecond := int64 (float64 (atomic .LoadInt32 (& consumerMessageCount )) / v )
59
- ConfirmedMessagesPerSecond := int64 (float64 (atomic .LoadInt32 (& confirmedMessageCount )) / v )
60
- logInfo ("Published %8v msg/s | Confirmed %8v msg/s | Consumed %6v msg/s | Cons. closed %3v | Pub errors %3v | %3v | %3v | msg sent: %3v |" ,
56
+ v := time .Now ().Sub (start ).Milliseconds ()
57
+ start = time .Now ()
58
+
59
+ PMessagesPerSecond := float64 (atomic .LoadInt32 (& publisherMessageCount )) / float64 (v ) * 1000
60
+ CMessagesPerSecond := float64 (atomic .LoadInt32 (& consumerMessageCount )) / float64 (v ) * 1000
61
+ ConfirmedMessagesPerSecond := float64 (atomic .LoadInt32 (& confirmedMessageCount )) / float64 (v ) * 1000
62
+
63
+ //if PMessagesPerSecond > 0 ||
64
+ // ConfirmedMessagesPerSecond > 0 ||
65
+ // CMessagesPerSecond > 0 ||
66
+ // consumersCloseCount > 0 ||
67
+ // publishErrors > 0 {
68
+ logInfo ("Published %8.2f msg/s | Confirmed %8.2f msg/s | Consumed %8.2f msg/s | Cons. closed %3v | Pub errors %3v | %3v | %3v | msg sent: %3v |" ,
61
69
PMessagesPerSecond , ConfirmedMessagesPerSecond , CMessagesPerSecond , consumersCloseCount , publishErrors , decodeRate (), decodeBody (), atomic .LoadInt64 (& messagesSent ))
70
+ //}
62
71
atomic .SwapInt32 (& publisherMessageCount , 0 )
63
72
atomic .SwapInt32 (& consumerMessageCount , 0 )
64
73
atomic .SwapInt32 (& confirmedMessageCount , 0 )
65
74
atomic .SwapInt32 (& notConfirmedMessageCount , 0 )
66
- start = time .Now ()
67
75
}
68
76
}
69
77
@@ -109,6 +117,11 @@ func startSimulation() error {
109
117
os .Exit (1 )
110
118
}
111
119
120
+ if rate > 0 && rate < batchSize {
121
+ batchSize = rate
122
+ logInfo ("Rate lower than batch size, move batch size: %d" , batchSize )
123
+ }
124
+
112
125
logInfo ("Silent (%s) Simulation, url: %s publishers: %d consumers: %d streams: %s " , stream .ClientVersion , rabbitmqBrokerUrl , publishers , consumers , streams )
113
126
114
127
err := initStreams ()
@@ -149,7 +162,10 @@ func randomSleep() {
149
162
func initStreams () error {
150
163
logInfo ("Declaring streams: %s" , streams )
151
164
env , err := stream .NewEnvironment (stream .NewEnvironmentOptions ().SetUris (
152
- rabbitmqBrokerUrl ))
165
+ rabbitmqBrokerUrl ).SetAddressResolver (stream.AddressResolver {
166
+ Host : rabbitmqBrokerUrl [0 ],
167
+ Port : 5552 ,
168
+ }))
153
169
if err != nil {
154
170
logError ("Error init stream connection: %s" , err )
155
171
return err
@@ -250,12 +266,10 @@ func startPublisher(streamName string) error {
250
266
go func (prod * ha.ReliableProducer , messages []message.StreamMessage ) {
251
267
for {
252
268
if rate > 0 {
253
- var v1 float64
254
- v1 = float64 (rate ) / float64 (batchSize )
269
+ rateWithBatchSize := float64 (rate ) / float64 (batchSize )
270
+ sleepAfterMessage := float64 (time .Second ) / rateWithBatchSize
271
+ time .Sleep (time .Duration (sleepAfterMessage ))
255
272
256
- sleep := float64 (100 ) / v1
257
- sleep = sleep * 10
258
- time .Sleep (time .Duration (sleep ) * time .Millisecond )
259
273
}
260
274
261
275
if variableRate > 0 {
@@ -269,8 +283,8 @@ func startPublisher(streamName string) error {
269
283
}
270
284
time .Sleep (time .Duration (sleep ) * time .Millisecond )
271
285
}
286
+ atomic .AddInt32 (& publisherMessageCount , int32 (len (arr )))
272
287
273
- atomic .AddInt32 (& publisherMessageCount , int32 (batchSize ))
274
288
for _ , streamMessage := range arr {
275
289
atomic .AddInt64 (& messagesSent , 1 )
276
290
err = prod .Send (streamMessage )
0 commit comments