1
0
mirror of https://github.com/redis/go-redis.git synced 2025-09-05 20:24:00 +03:00

feat(push): reading optimization for Linux

Optimize the peeking on newly acquired connection on *unix. Use syscall
to peek on the socket instead of blocking for a fixed amount of time.
This won't work on Windows, hence the `MaybeHasData` will always return
true on Windows and the client will have to block for a given time to
actually peek on the socket.

*Time to complete N HSET operations (individual commands)*

| Batch Size | Before (total sec) | After (total sec) | Time Saved | % Faster |
|------------|-------------------|------------------|------------|----------|
| 100 ops    | 0.0172           | 0.0133           | 0.0038     | **22.4%** |
| 1K ops     | 0.178            | 0.133            | 0.045      | **25.3%** |
| 10K ops    | 1.72             | 1.28             | 0.44       | **25.6%** |
| 100K ops   | 17.1             | 13.4             | 3.7        | **22.0%** |
This commit is contained in:
Nedyalko Dyakov
2025-07-24 11:46:00 +03:00
parent 72c24d59f4
commit af6a103457
6 changed files with 274 additions and 27 deletions

View File

@@ -57,6 +57,7 @@ func (p *Processor) ProcessPendingNotifications(ctx context.Context, handlerCtx
replyType, err := rd.PeekReplyType()
if err != nil {
// No more data available or error reading
// if timeout, it will be handled by the caller
break
}
@@ -144,6 +145,7 @@ func (v *VoidProcessor) ProcessPendingNotifications(_ context.Context, handlerCt
replyType, err := rd.PeekReplyType()
if err != nil {
// No more data available or error reading
// if timeout, it will be handled by the caller
break
}
@@ -176,7 +178,7 @@ func (v *VoidProcessor) ProcessPendingNotifications(_ context.Context, handlerCt
func willHandleNotificationInClient(notificationType string) bool {
switch notificationType {
// Pub/Sub notifications - handled by pub/sub system
case "message", // Regular pub/sub message
case "message", // Regular pub/sub message
"pmessage", // Pattern pub/sub message
"subscribe", // Subscription confirmation
"unsubscribe", // Unsubscription confirmation