@@ -127,25 +127,36 @@ func benchmarkHSETOperationsConcurrent(b *testing.B, rdb *redis.Client, ctx cont
127127 // Perform the specified number of HSET operations
128128
129129 wg := sync.WaitGroup {}
130- wg .Add (operations )
131130 timesCh := make (chan time.Duration , operations )
131+ errCh := make (chan error , operations )
132+
132133 for j := 0 ; j < operations ; j ++ {
134+ wg .Add (1 )
133135 go func (j int ) {
134136 defer wg .Done ()
135137 field := fmt .Sprintf ("field_%d" , j )
136138 value := fmt .Sprintf ("value_%d" , j )
137139
138140 err := rdb .HSet (ctx , hashKey , field , value ).Err ()
139141 if err != nil {
140- b .Fatalf ("HSET operation failed: %v" , err )
142+ errCh <- err
143+ return
141144 }
142145 timesCh <- time .Since (startTime )
143146 }(j )
144- wg .Wait ()
145- close (timesCh )
146- for d := range timesCh {
147- totalTimes = append (totalTimes , d )
148- }
147+ }
148+
149+ wg .Wait ()
150+ close (timesCh )
151+ close (errCh )
152+
153+ // Check for errors
154+ for err := range errCh {
155+ b .Errorf ("HSET operation failed: %v" , err )
156+ }
157+
158+ for d := range timesCh {
159+ totalTimes = append (totalTimes , d )
149160 }
150161 }
151162
@@ -206,7 +217,7 @@ func BenchmarkHSET_Concurrent(b *testing.B) {
206217 rdb := redis .NewClient (& redis.Options {
207218 Addr : "localhost:6379" ,
208219 DB : 0 ,
209- PoolSize : 1000 ,
220+ PoolSize : 100 ,
210221 })
211222 defer rdb .Close ()
212223
@@ -220,7 +231,8 @@ func BenchmarkHSET_Concurrent(b *testing.B) {
220231 rdb .FlushDB (ctx )
221232 }()
222233
223- scales := []int {1 , 10 , 100 , 1000 , 10000 , 100000 }
234+ // Reduced scales to avoid overwhelming the system with too many concurrent goroutines
235+ scales := []int {1 , 10 , 100 , 1000 }
224236
225237 for _ , scale := range scales {
226238 b .Run (fmt .Sprintf ("HSET_%d_operations_concurrent" , scale ), func (b * testing.B ) {
0 commit comments