Skip to content

Autopipeline - use setImmediate instead of queueMicrotask (improves performance) #2516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ If don't want to queue commands in memory until a new socket is established, set

## How are commands batched?

Commands are pipelined using [`queueMicrotask`](https://nodejs.org/api/globals.html#globals_queuemicrotask_callback).
Commands are pipelined using [`setImmediate`](https://nodejs.org/api/timers.html#setimmediatecallback-args).

If `socket.write()` returns `false`—meaning that ["all or part of the data was queued in user memory"](https://nodejs.org/api/net.html#net_socket_write_data_encoding_callback:~:text=all%20or%20part%20of%20the%20data%20was%20queued%20in%20user%20memory)—the commands will stack in memory until the [`drain`](https://nodejs.org/api/net.html#net_event_drain) event is fired.

Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/client/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export default class RedisSocket extends EventEmitter {
this.#socket.cork();
this.#isCorked = true;

queueMicrotask(() => {
setImmediate(() => {
this.#socket?.uncork();
this.#isCorked = false;
});
Expand Down