In Node.js, would it be best to do a createClient() for each individual HTTP request or user, or would it be better to re-use the same client for all requests? Do you still get the speed of several parallel clients with just one?
在Node.js中,最好为每个单独的HTTP请求或用户执行createClient(),还是最好为所有请求重用相同的客户端?你还只用一个并行的几个并行客户端的速度吗?
1 个解决方案
#1
7
In Node.js, would it be best to do a createClient() for each individual HTTP request or user, or would it be better to re-use the same client for all requests?
在Node.js中,最好为每个单独的HTTP请求或用户执行createClient(),还是最好为所有请求重用相同的客户端?
You should reuse the redis client connection and persist it during the lifetime of your program since establishing a new connection have some initial overhead which can be avoided with already connected client.
您应该重用redis客户端连接并在程序的生命周期内保留它,因为建立新连接会产生一些初始开销,这可以通过已连接的客户端来避免。
Do you still get the speed of several parallel clients with just one?
你还只用一个并行的几个并行客户端的速度吗?
You might get some performance improvements with a pool of several parallel clients (limited number, not dedicated connection for each individual HTTP request or user), but the question is how would you deal with the concurrency of executed commands. Although redis is built to handle hundreds or thousands of simultaneously connected clients, connection pooling is something which, I think, should be controlled by the client library you are using. However you should use two parallel connections if you are simultaneously using redis for listening on some pub/sub channel and at the same time executing normal commands.
您可以通过多个并行客户端池(有限数量,而不是每个单独的HTTP请求或用户的专用连接)获得一些性能改进,但问题是如何处理已执行命令的并发性。虽然redis是为处理数百或数千个同时连接的客户端而构建的,但我认为连接池应该由您正在使用的客户端库控制。但是,如果同时使用redis监听某个发布/订阅通道并同时执行常规命令,则应使用两个并行连接。
#1
7
In Node.js, would it be best to do a createClient() for each individual HTTP request or user, or would it be better to re-use the same client for all requests?
在Node.js中,最好为每个单独的HTTP请求或用户执行createClient(),还是最好为所有请求重用相同的客户端?
You should reuse the redis client connection and persist it during the lifetime of your program since establishing a new connection have some initial overhead which can be avoided with already connected client.
您应该重用redis客户端连接并在程序的生命周期内保留它,因为建立新连接会产生一些初始开销,这可以通过已连接的客户端来避免。
Do you still get the speed of several parallel clients with just one?
你还只用一个并行的几个并行客户端的速度吗?
You might get some performance improvements with a pool of several parallel clients (limited number, not dedicated connection for each individual HTTP request or user), but the question is how would you deal with the concurrency of executed commands. Although redis is built to handle hundreds or thousands of simultaneously connected clients, connection pooling is something which, I think, should be controlled by the client library you are using. However you should use two parallel connections if you are simultaneously using redis for listening on some pub/sub channel and at the same time executing normal commands.
您可以通过多个并行客户端池(有限数量,而不是每个单独的HTTP请求或用户的专用连接)获得一些性能改进,但问题是如何处理已执行命令的并发性。虽然redis是为处理数百或数千个同时连接的客户端而构建的,但我认为连接池应该由您正在使用的客户端库控制。但是,如果同时使用redis监听某个发布/订阅通道并同时执行常规命令,则应使用两个并行连接。