Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres Hstore vs. Redis - performance wise

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

Our application is written in NodeJS. Two questions:

  • 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?

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).

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.

Thanks!

like image 482
jribeiro Avatar asked Feb 05 '12 21:02

jribeiro


People also ask

How much faster is Redis than Postgres?

If anything, I'm surprised that the Redis solution is _only_ 16-20x faster than PostgreSQL given what appears to be happening.

What is Hstore?

hstore is a PostgreSQL extension that implements the hstore data type. It's a key-value data type for PostgreSQL that's been around since before JSON and JSONB data types were added.

What is Postgres Redis?

A Redis in-memory database cache allows you to access frequently used data from your server's RAM. This minimizes unnecessarily load and roundtrips to your PostgreSQL database server.


2 Answers

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 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.

like image 119
Matt Sergeant Avatar answered Oct 03 '22 22:10

Matt Sergeant


Using PostgreSQL as session manager is usually bad idea.

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).

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.

like image 25
Pavel Stehule Avatar answered Oct 03 '22 22:10

Pavel Stehule