Blog
Sorry, your browser does not support inline SVG.

Comparing YottaDB and Redis Using 3n+1 Sequences

K.S. Bhaskar

TL;DR: Performance Comparisons has instructions for you build a Docker container that allows you to make a side by side comparison of Redis,[1] Xider™,[2] and YottaDB. The image above is a screenshot of Xider and YottaDB outperforming Redis with a 32-process workload.

In 2025, the Journal of Computing Languages (JCL) plans a special issue recognizing 30 years of Lua. Since YottaDB has a native Lua API, we have submitted an article to JCL for that issue. A preprint of that article is on arXiv. The article compares the Redis and YottaDB APIs, and delves deeper into the performance comparison described below.

The choice of workload is important when benchmarking databases.

  • A realistic benchmark must perform a large number of accesses, in order to remove timing jitter.
  • Accesses must be different types, as real world workloads are not monolithic in their databases accesses.
  • The benchmark must run on a variety of computing hardware.
  • The benchmark must give consistent results on repeated runs.
  • The workload should be simple and understandable.

Computing the lengths of 3n+1 sequences meets these requirements. Given an integer n, the next number in the sequence is (a) n÷2 if n is even, and (b) 3n+1 if n is odd. The Collatz Conjecture, one of the great unproven results of number theory, asserts that all such sequences end in 1, i.e., there are no loops, and no sequences of infinite length. For example:

  • 3 → 10 → 5 → 16 → 8 → 4 → 2 → 1
  • 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1

Note that the sequences starting with 3 and 13 both meet at 10. If there are two processes, one computing the lengths of 3n+1 sequences starting with 13, and the other those of sequences starting with 3, and if they use a database to store the results as they work, then the process which reaches 10 later can simply use the results of the earlier process which has already computed and stored the results for the rest of the sequence.

The picture[3] is a visualization of the 3n+1 sequences of the numbers through 20,000, illustrating the convergence of the sequences, with all eventually converging on 1.

The problem is simple enough for programs to be easily written in virtually any language. While our intent in our blog post Solving the 3n+1 Problem with YottaDB was to compare programming languages, the programs can also be used to compare databases, and database APIs. In particular, we can compare Redis, YottaDB, and Xider. Xider is an API layer that allows YottaDB to provide applications with a Redis-compatible API, with two options:

  • over TCP using the Redis Serialization Protocol (RESP); and
  • for databases residing on the same machine as the client, we offer a direct connection to the database engine using Python and Lua APIs. The API is the same as the TCP / RESP API, except that it calls the database engine using our in-process native API calls. 

In addition to the above two comparisons, which use the same program for Redis and Xider, there are also Lua, Python, and M programs that directly access the database, i.e., without going through a Redis compatible API layer.

We invite you to compare Redis, Xider, and YottaDB for yourself, and send us your comments.


[1] Redis is a registered trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd. Any use by YottaDB is for referential purposes only and does not indicate any sponsorship, endorsement or affiliation between Redis and YottaDB.

[2] As Xider is still under development, not all Redis functionality is available. Any implemented functionality is upward compatible with Redis. Since Xider is continuously released, if functionality your application needs is not available, please check whether there is an Issue for it, and create one if there isn’t one. You can create a GitLab notification to stay informed with Xider updates.

Published on November 26, 2024