生菜:反应API的共享连接(Lettuce: Shared connection for reactive API)

编程入门 行业动态 更新时间:2024-10-24 06:26:24
生菜:反应API的共享连接(Lettuce: Shared connection for reactive API)

我将我目前的项目从Jedis移植到Lettuce。

是否可以将共享连接用于反应式API? 只要我不调用阻塞和事务操作,如BLPOP和MULTI / EXEC?

我应该通过反应API使用池化连接进行交易吗?

是否可以通过反应式API管道命令? 我应该使用专用连接吗?

I'm porting my current project from Jedis to Lettuce.

Is it ok to use shared connection for reactive API? As long as I don't invoke blocking and transactional operations such as BLPOP and MULTI/EXEC?

Should I use pooled connections for transactions through reactive API?

Is it possible to pipeline commands through reactive API? Should I use dedicated connection for that?

最满意答案

在多个线程之间共享一个连接是预期的用法。 原因有很多:

连接是线程安全的。 Redis是单线程的。 使用多个连接到一个主机显然毫无意义,因为没有Redis处理并行性,因此没有性能提升。 连接池打开多个连接。 虽然这可能对事务和阻塞命令隔离有意义,但池可能会导致性能下降。 从一个Redis服务器接收来自多个应用程序服务器的连接,一开始就处于忙碌状态,接受和管理连接。 单线程Redis性质也影响接受和删除连接的过程。

关于流水线:在将后续命令发送到Redis之前,生菜不会等待命令完成,这意味着生菜默认使用流水线操作。 防止流水线操作的唯一方法是在命令调用之外进行同步。

每个命令都直接刷新到TCP连接。 生菜可以使用批处理将命令分组,然后将它们刷新到连接。 命令冲洗是一种手动操作,更多用于批量加载而不是用于反应性使用。

还有两件事:

维基应该更深入地回答您的问题: https : //github.com/mp911de/lettuce/wiki 生菜从RxJava 1迁移到基于Project Reactor的Reactive Streams API。 这种情况发生在生菜5.0中,其中第一个β已经可用。

HTH,

标记

Sharing one connection amongst multiple threads is the intended usage. There are multiple reasons:

Connections are threadsafe. Redis is single-threaded. Using multiple connections to one host makes obviously no sense as there is no performance gain due to the lack of Redis processing parallelism. Connection pooling opens multiple connections. Although this might make sense for transaction and blocking command isolation, pooling may cause performance degradation. A single Redis server that receives connections from multiple application servers is kept busy in the first place with accepting and managing connections. The single-threaded Redis nature affects also the process of accepting and dropping connections.

Regarding pipelining: lettuce does not await command completion before sending subsequent commands to Redis which means lettuce uses pipelining by default. The only way to prevent pipelining is outside synchronization on command invocation.

Each command is flushed directly to the TCP connection. Lettuce can use batching to group commands before flushing them to the connection. Command flushing is a manual thing and more intended for bulk loading and not for reactive use.

There are two more things:

The wiki should answer your questions in a deeper level of detail: https://github.com/mp911de/lettuce/wiki Lettuce migrates away from RxJava 1 to a Reactive Streams API based on Project Reactor. That happens with lettuce 5.0 of which the first beta is already available.

HTH,

Mark

更多推荐

本文发布于:2023-07-25 10:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1260017.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:生菜   API   Lettuce   reactive   connection

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!