postgresql Postgres Hstore 与 Redis - 性能明智

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9153157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:36:59  来源:igfitidea点击:

Postgres Hstore vs. Redis - performance wise

performancepostgresqlnode.jsrediskey-value-store

提问by jribeiro

I read aboutHStores in Postgres something that is offered by Redis as well.

我在 Postgres 中读到了一些 Redis 提供的关于HStores 的内容

Our application is written in NodeJS. Two questions:

我们的应用程序是用 NodeJS 编写的。两个问题:

  • Performance-wise, is Postgres HStore comparable to Redis?

  • for session storage, what would you recommend--Redis, or Postgres with some other kind of data type (like HStore, or maybe even the usual relational table)? And how bad is one option vs the other?

  • 在性能方面,Postgres HStore 是否可以与 Redis 相媲美?

  • 对于会话存储,您会推荐什么 - Redis 或具有其他类型数据类型的 Postgres(例如 HStore,甚至可能是通常的关系表)?一种选择与另一种选择有多糟糕?

Another constraint, is that we will need to use the data that is already in PostgreSQL and combine it with the active sessions (which we aren't sure where to store at this point, if in Redis or PostgreSQL).

另一个限制是,我们需要使用 PostgreSQL 中已经存在的数据并将其与活动会话结合起来(如果在 Redis 或 PostgreSQL 中,我们目前不确定将其存储在哪里)。

From what we have read, we have been pointed out to use Redis as a Session manager, but due to the PostgreSQL constraint, we are not sure how to combine both and the possible performance issues that may arise.

从我们读到的内容来看,我们已经被指出使用 Redis 作为 Session 管理器,但是由于 PostgreSQL 的限制,我们不确定如何将两者结合起来以及可能出现的性能问题。

Thanks!

谢谢!

回答by Matt Sergeant

Redis will be faster than Postgres because Pg offers reliability guarantees on your data (when the transaction is committed, it is guaranteed to be on disk), whereas Redis has a concept of writing to disk when it feels like it, so shouldn't be used for critical data.

Redis 会比 Postgres 更快,因为 Pg 为你的数据提供可靠性保证(当事务提交时,它保证在磁盘上),而 Redis 有一个感觉时写入磁盘的概念,所以不应该用于关键数据。

Redis seems like a good option for your session data, or heck even store in a cookie or in your client side Javascript. But if you need data from your database on every request then it might not be even worth involving Redis. It very much depends on your application.

Redis 似乎是您会话数据的不错选择,甚至可以存储在 cookie 或客户端 Javascript 中。但是,如果您在每次请求时都需要数据库中的数据,那么甚至不值得使用 Redis。这在很大程度上取决于您的应用程序。

回答by Pavel Stehule

Using PostgreSQL as session manager is usually bad idea.

使用 PostgreSQL 作为会话管理器通常是个坏主意。

For older than 9.1 was physical limit of transaction per second based on persistent media parameters. For session management you usually don't need MGA (because there are not collision) and it means so MGA is overhead and databases without MGA and ACID must be significantly faster (10 or 100).

对于 9.1 之前的版本,每秒事务的物理限制基于持久媒体参数。对于会话管理,您通常不需要 MGA(因为没有冲突),这意味着 MGA 是开销,没有 MGA 和 ACID 的数据库必须明显更快(10 或 100)。

I know a use case, where PostgreSQL was used for session management and Performance was really terrible and unstable - it was eshop with about 10000 living sessions. When session management was moved to memcached, then performance and stability was significantly increased. PostgreSQL can be used for 100 living session without problem probably. For higher numbers there are better tools.

我知道一个用例,其中 PostgreSQL 用于会话管理,而性能非常糟糕且不稳定——它是 eshop,大约有 10000 个活动会话。当会话管理移至 memcached 时,性能和稳定性显着提高。PostgreSQL 大概可以用于 100 个活动会话而没有问题。对于更高的数字,有更好的工具。