| 211 | } |
| 212 | |
| 213 | func BenchmarkHSET_Concurrent(b *testing.B) { |
| 214 | ctx := context.Background() |
| 215 | |
| 216 | // Setup Redis client |
| 217 | rdb := redis.NewClient(&redis.Options{ |
| 218 | Addr: "localhost:6379", |
| 219 | DB: 0, |
| 220 | PoolSize: 100, |
| 221 | }) |
| 222 | defer rdb.Close() |
| 223 | |
| 224 | // Test connection |
| 225 | if err := rdb.Ping(ctx).Err(); err != nil { |
| 226 | b.Skipf("Redis server not available: %v", err) |
| 227 | } |
| 228 | |
| 229 | // Clean up before and after tests |
| 230 | defer func() { |
| 231 | rdb.FlushDB(ctx) |
| 232 | }() |
| 233 | |
| 234 | // Reduced scales to avoid overwhelming the system with too many concurrent goroutines |
| 235 | scales := []int{1, 10, 100, 1000} |
| 236 | |
| 237 | for _, scale := range scales { |
| 238 | b.Run(fmt.Sprintf("HSET_%d_operations_concurrent", scale), func(b *testing.B) { |
| 239 | benchmarkHSETOperationsConcurrent(b, rdb, ctx, scale) |
| 240 | }) |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | // benchmarkHSETPipelined performs HSET benchmark using pipelining |
| 245 | func benchmarkHSETPipelined(b *testing.B, rdb *redis.Client, ctx context.Context, operations int) { |