News for hackers. Stuff that matters.
Re:Redis Re-Implemented with SQLite by yuppiepuppie on Sunday April 14, 2024 @02:52PM (#40033391)
Curious, What’s the use case?
Re:Redis Re-Implemented with SQLite by jitl on Sunday April 14, 2024 @03:01PM (#40033473)
Redis drops data semi randomly when under memory pressure.

If you use Redis for queue tasks (this is popular in Rails and Django/Python web services), that means that during an incident where your queue jobs are getting added faster than they’re removed, you’re going to lose jobs if the incident goes on long enough.

Re:Redis Re-Implemented with SQLite by byroot on Sunday April 14, 2024 @03:08PM (#40033526)
That depends on how the `maxmemory-policy` is configured, and queue systems based on Redis will tell you not to allow eviction. https://github.com/sidekiq/sidekiq/wiki/Using-Redis#memory (it even logs a warnings if it detects your Redis is misconfigured IIRC).
Re:Redis Re-Implemented with SQLite by kiitos on Sunday April 14, 2024 @03:39PM (#40033762)
Well, of course! Redis is not (and has never been) a database, it's a data structure server, at best described as a cache. If jobs are added faster than they're removed, this is straight queueing theory 101 -- ideally you'd reject jobs at add-time, but otherwise you have to drop them.
Re:Redis Re-Implemented with SQLite by gnarbarian on Sunday April 14, 2024 @04:16PM (#40034080)
Right. I think Redis hitting the disk would be a terrible tradeoff compared to making a new backend call. it probably wouldn't save you much time and I imagine it would lead to very strange and unpredictable behavior on the front end or trying to debug latency or data issues downstream
Re:Redis Re-Implemented with SQLite by prisenco on Sunday April 14, 2024 @04:04PM (#40033986)
Since Redis is an in-memory cache, and already doesn't guarantee the data, would it make sense to set PRAGMA SYNCHRONOUS on nalgeon to OFF to boost performance to something closer to standard Redis?
Re:Redis Re-Implemented with SQLite by qwertox on Sunday April 14, 2024 @02:55PM (#40033419)
My same thought, because some don't require much memory.
Re:Redis Re-Implemented with SQLite by akie on Sunday April 14, 2024 @03:06PM (#40033509)
The use case is caching 20 million API responses that almost never change, each about 20kb of JSON, for a high traffic site.

Yes, I can pay for a 400Gb RAM instance of Redis, but it's expensive.

I can also cache it on disk, but then I need to think about cache expiration myself.

Or I can use something appropriate like a document database, but then I need additional code & additional configuration because we otherwise don't need that piece of infrastructure in our stack.

It would be a lot easier if I could just store it in Redis with the other (more reasonably sized) things that I need to cache.

Re:Redis Re-Implemented with SQLite by yuliyp on Sunday April 14, 2024 @04:23PM (#40034135)
You're trying to get redis to be what it isn't. Use a thing that has the properties you want: a document or relational database. If you insist on this then running a system that allows a ton of swap onto a reasonably fast disk might work, but is still gonna perform worse than a system that's designed for concurrently serving queries of wildly differing latencies.
Re:Redis Re-Implemented with SQLite by minitech on Sunday April 14, 2024 @08:03PM (#40035668)
Yes, that was the context: a Redis alternative to support the same operations but be what Redis isn’t.
Re:Redis Re-Implemented with SQLite by danpat on Sunday April 14, 2024 @04:11PM (#40034043)
Or shard it - divide your objects up based on some criteria (hash the name of the object, use the first N digits of the hash to assign to a shard), and distribute them across multiple redis instances. Yes, you then need to maintain some client code to pick the right redis instance to fetch from, but you can now pick the most $/memory efficient instance types to run redis, and you don't have to worry about introducing disk read latency and the edge cases that brings with it.

Edit: looks like redis has some built-in support for data sharding when used as a cluster (https://redis.io/docs/latest/commands/cluster-shards/) - I haven't used that, so not sure how easy it is to apply, and exactly what you'd have to change.

Re:Redis Re-Implemented with SQLite by yuliyp on Sunday April 14, 2024 @04:19PM (#40034100)
Sharding doesn't help here at all. They'd still need the same amount of RAM to house all the data in redis.
Re:Redis Re-Implemented with SQLite by reese_john on Sunday April 14, 2024 @04:15PM (#40034072)
You could try using Amazon S3 Express, a low-latency alternative for S3 buckets [0]. I imagine cache invalidation would be relatively simple to implement using lifecycle policies.

https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-exp...

Re:Redis Re-Implemented with SQLite by 0cf8612b2e1e on Sunday April 14, 2024 @04:10PM (#40034031)
Would DiskCache work for you? Runs via SQLite memory or persisted file database. Thread safe, has various expiration controls, etc.

https://grantjenks.com/docs/diskcache/tutorial.html

Re:Redis Re-Implemented with SQLite by Nican on Sunday April 14, 2024 @03:16PM (#40033589)
This looks like a good use case for ScyllaDB with Compression and TTL. It is pretty simple to setup a single-node instance.

If you rather have something in-process and writes to disk, to avoid extra infrastructure, I would also recommend RocksDB with Compression and TTL.

Re:Redis Re-Implemented with SQLite by seddonm1 on Sunday April 14, 2024 @04:36PM (#40034253)
In other abuses of SQLite, I wrote a tool [0] that exposes blobs in SQLite via an Amazon S3 API. It doesn't do expiry (but that would be easy enough to add if S3 does it).

We were using it to manage a millions of images for machine learning as many tools support S3 and the ability to add custom metadata to objects is useful (harder with files). It is one SQLite database per bucket but at the bucket level it is transactional.

0: https://github.com/seddonm1/s3ite

Re:Redis Re-Implemented with SQLite by phamilton on Sunday April 14, 2024 @04:40PM (#40034284)
A few things:

Redis Data Tiering - Redis Enterprise and AWS Elasticache for Redis support data tiering (using SSD for 80% of the dataset and moving things in and out). On AWS, a cache.r6gd.4xlarge with 100GB of memory can handle 500GB of data.

Local Files

> I can also cache it on disk, but then I need to think about cache expiration myself.

Is the challenge that you need it shared among many machines? On a single machine you can put 20 million files in a directory hierarchy and let the fs cache keep things hot in memory as needed. Or use SQLite which will only load the pages needed for each query and also rely on the fs cache.

S3 - An interesting solution is one of the SQLite S3 VFS's. Those will query S3 fairly efficiently for specific data in a large dataset.

Re:Redis Re-Implemented with SQLite by kiitos on Sunday April 14, 2024 @05:03PM (#40034461)
Redis is an in-memory cache by definition. If you don't want to cache in-memory, then don't use Redis.
Re:Redis Re-Implemented with SQLite by tayo42 on Sunday April 14, 2024 @09:41PM (#40036262)
Have you looked at varnish for caching api responses? Varnish let's you back it with disk and relies on page cache to keep more accessed items in memory.

If the reverse proxy thing doesn't work I think memcached has two level storage like that now iirc

Re:Redis Re-Implemented with SQLite by mannyv on Monday April 15, 2024 @01:26AM (#40037321)
If you're caching 20m api requests that almost never change use s3. I mean heck, it's cheaper, can be cdn'd, and can be pipelined by the browser.
Re:Redis Re-Implemented with SQLite by emmanueloga_ on Monday April 15, 2024 @06:50AM (#40038821)
Check memcached "extstore" [1].

--

1: https://github.com/memcached/memcached/wiki/Extstore

Re:Redis Re-Implemented with SQLite by noncoml on Sunday April 14, 2024 @03:13PM (#40033564)
Using a hammer like a screwdriver