MSOpenTech’s Redis on Windows
We strive to have a stable, functionally equivalent and comparably performing version of Redis on
Windows. We have achieved performance nearly identical to the POSIX version running head-to-head
on identical hardware across the network. Aside from feature differences that help Redis take
advantage of the Windows infrastructure, our version of Redis should work in most situations with the
identical setup and configuration that one would use on a POSIX operating system.
How is Redis on Windows implemented?
Redis is a C code base that compiles under Visual Studio. Most of the code compiles with only minor
changes (due to syntactical differences between compilers and low-level API differences on Windows).
There are a few areas where there are significant differences in how efficient Windows programs
operate relative to POSIX programs. We have encapsulated most these differences in a platform specific
library. The areas where there are significant differences are:
• Networking APIs
• POSIX File Descriptors
• POSIX fork()
• Logging
• Windows Services API
Networking Differences
The Windows networking stack is split between user mode code and kernel mode code. Transitions
between user and kernel mode are expensive operations. The POSIX networking APIs on Windows
utilize a programming model that incurs significant performance loss due to the kernel/user mode
transitions. Efficient Windows networking code instead uses the IO Completion Port model to reduce
the impact of this behavior. The APIs used and the programming model for IO Completion is different
enough that we were forced to implement a new networking layer in Redis.
File Descriptors
In a POSIX operating system, all data sources (files, pipes, sockets, mail slots, etc.) are referenced in code
with a handle called a file descriptor. These are low value integers that increment by one with each
successive file descriptor creation. All POSIX APIs that work with file descriptors will function without the
programmer having to know what kind of data source a file descriptor represents. On Windows, each
kind of data source has a separate kind of HANDLE. APIs that work with one HANDLE type will not work
with another kind of HANDLE. In order to make Redis operate with its assumptions about file descriptor
values and data source agnosticism, we implemented a Redis File Descriptor API layer.
fork()
The POSIX version of Redis uses the fork() API. There is no equivalent in Windows, and it is an
exceedingly difficult API to completely simulate. For most of the uses of fork() we have used Windows
specific programming idioms to bypass the need to use a fork()-like API. The one case where we could
not do so was with the point-in-time heap snapshot behavior that the Redis persistence model is based
on. We tried several different approaches to work around the need for a fork()-like API, but always ran
into significant performance penalties and stability issues.