Skip to content

adarqui/xedis-test

Repository files navigation

XEDIS!
-----'

This is a little test of 'xedis' (embedded redis), or what xedis could be. Xedis is just an embedded form of redis, which doesn't really exist. The benchmarks below show the obvious (massive) performance increases by embedding redis directly within a program, due to reduction in system calls/context switches etc.

If xedis actually existed, what could you do?

1. Move extremely intense/large sets of redis operations out to it's own process, SAVE the dump.rdb to a session_xyz.rdb, and then import it into your actual redis server. In order to avoid conflicts, import could prepend a namespace or you could do it yourself in the self contained xedis processing code.
2. Use the power of redis to persist your program's state in a format that can be loaded right into redis.
3. Use data structure operations that are familiar and "portable" to other apps, directly within your program, without anything slowing you down.
4. There's more, trust me.


A quick example:
---------------'

In the benchmarks below, you can see two tests performed using xedis (embedded redis) and hiredis (C api communicating with a normal redis server). The xedis benchmark lasts 22 seconds, while the hiredis benchmark takes 9 minutes. If for some reason, you had to perform quite a bit of these operations on a frequent basis, maybe another approach would work:

redis-cli BGSAVE -> may take a minute or so
load up a xedis worker with that dump.rdb
process everything in seconds
redis-cli IMPORT DIFFERENCE /tmp/xedis-session-32412312.rdb <-- command doesn't exist yet, but it should?

Now you may have been able to shave several minutes off of the processing time.

Makes sense? Somewhat? (yes!)


Benchmarks:
----------'

Below you will see a comparison between xedis (first test) & hiredis (second test).

The test is as follows:

	time ./z-test-xedis 5 0 2 1:1000000 2 3:1000000 2 4:set1,0,1000000 2

	Perform 5 iterations of:

		0 - FLUSHALL
		2 - KEYS *
		1:1000000 - set 1 million keys named (0-1000000) with value "world"
		2 - KEYS *
		3:1000000 - perform INCR on the "incr" key, 1 million times
		2 - KEYS *
		4:set1,0,1000000 - perform 1 million SADD's on the key set1, from 0 to 1000000
		2 - KEYS *

	then SAVE (to dump.rdb)


RESULTS:

	xedis:

real    0m22.980s
user    0m21.904s
sys     0m0.460s

	hiredis:

real    9m2.484s
user    2m11.048s
sys     3m36.968s



How to build:
------------'

	make
	# make will error at the end, that's fine
	cd src/
	./z-make.sh
	./z-test-xedis
	./z-test-hiredis


To see modified files:
---------------------'

git log

	commit message "xedis"







Come stop by #jumping on efnet to nerd out.







BENCHMARK: XEDIS:
----------------'

adarqui@null:~/dev/xedis/src(unstable+*)$ time ./z-test-xedis 5 0 2 1:1000000 2 3:1000000 2 4:set1,0,1000000 2

[29049] 17 Nov 02:44:50.849 # Warning: no config file specified, using the default config. In order to specify a config file use ./z-test-xedis /path/to/redis.conf
[29049] 17 Nov 02:44:50.850 # Unable to set the max number of files limit to 10032 (Operation not permitted), setting the max clients configuration to 3984.
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 2.9.11 (b2f83439/1) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in stand alone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 29049
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

[29049] 17 Nov 02:44:50.851 # Server started, Redis version 2.9.11
[29049] 17 Nov 02:44:50.851 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[29049] 17 Nov 02:44:51.225 * DB loaded from disk: 0.374 seconds
[29049] 17 Nov 02:44:51.225 * The server is now ready to accept connections on port 6379
apply_op: arg_index=0 ops_sz=6
z_flushall: 0
[29049] 17 Nov 02:44:51.714 * DB saved on disk
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=1 ops_sz=6
z_set_incremental: 1000000
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=3 ops_sz=6
z_incr_key: 1000000
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=4 ops_sz=6
z_sadd_incremental: set1,0,1000000
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=0 ops_sz=6
z_flushall: 0
[29049] 17 Nov 02:44:55.891 * DB saved on disk
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=1 ops_sz=6
z_set_incremental: 1000000
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=3 ops_sz=6
z_incr_key: 1000000
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=4 ops_sz=6
z_sadd_incremental: set1,0,1000000
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=0 ops_sz=6
z_flushall: 0
[29049] 17 Nov 02:45:00.236 * DB saved on disk
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=1 ops_sz=6
z_set_incremental: 1000000
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=3 ops_sz=6
z_incr_key: 1000000
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=4 ops_sz=6
z_sadd_incremental: set1,0,1000000
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=0 ops_sz=6
z_flushall: 0
[29049] 17 Nov 02:45:04.703 * DB saved on disk
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=1 ops_sz=6
z_set_incremental: 1000000
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=3 ops_sz=6
z_incr_key: 1000000
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=4 ops_sz=6
z_sadd_incremental: set1,0,1000000
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=0 ops_sz=6
z_flushall: 0
[29049] 17 Nov 02:45:09.204 * DB saved on disk
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=1 ops_sz=6
z_set_incremental: 1000000
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=3 ops_sz=6
z_incr_key: 1000000
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
apply_op: arg_index=4 ops_sz=6
z_sadd_incremental: set1,0,1000000
apply_op: arg_index=2 ops_sz=6
z_keys_star: 2
[29049] 17 Nov 02:45:13.749 * DB saved on disk

real    0m22.980s
user    0m21.904s
sys     0m0.460s








BENCHMARK: HIREDIS:
------------------'

adarqui@null:~/dev/xedis/src(unstable+*)$ time ./z-test-hiredis 5 0 2 1:1000000 2 3:1000000 2 4:set1,0,1000000 2
apply_op: arg_index=0 ops_sz=5
z_flushall: 0
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=1 ops_sz=5
z_set_incremental: 1000000
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=3 ops_sz=5
z_incr_key: 1000000
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=4 ops_sz=5
z_sadd_incremental: set1,0,1000000
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=0 ops_sz=5
z_flushall: 0
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=1 ops_sz=5
z_set_incremental: 1000000
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=3 ops_sz=5
z_incr_key: 1000000
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=4 ops_sz=5
z_sadd_incremental: set1,0,1000000
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=0 ops_sz=5
z_flushall: 0
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=1 ops_sz=5
z_set_incremental: 1000000
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=3 ops_sz=5
z_incr_key: 1000000
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=4 ops_sz=5
z_sadd_incremental: set1,0,1000000
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=0 ops_sz=5
z_flushall: 0
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=1 ops_sz=5
z_set_incremental: 1000000
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=3 ops_sz=5
z_incr_key: 1000000
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=4 ops_sz=5
z_sadd_incremental: set1,0,1000000
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=0 ops_sz=5
z_flushall: 0
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=1 ops_sz=5
z_set_incremental: 1000000
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=3 ops_sz=5
z_incr_key: 1000000
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2
apply_op: arg_index=4 ops_sz=5
z_sadd_incremental: set1,0,1000000
apply_op: arg_index=2 ops_sz=5
z_keys_star: 2

real    9m2.484s
user    2m11.048s
sys     3m36.968s
















Where to find complete Redis documentation?
-------------------------------------------

This README is just a fast "quick start" document. You can find more detailed
documentation at http://redis.io

Building Redis
--------------

Redis can be compiled and used on Linux, OSX, OpenBSD, NetBSD, FreeBSD.
We support big endian and little endian architectures.

It may compile on Solaris derived systems (for instance SmartOS) but our
support for this platform is "best effort" and Redis is not guaranteed to
work as well as in Linux, OSX, and *BSD there.

It is as simple as:

    % make

You can run a 32 bit Redis binary using:

    % make 32bit

After building Redis is a good idea to test it, using:

    % make test

Fixing problems building 32 bit binaries
---------

If after building Redis with a 32 bit target you need to rebuild it
with a 64 bit target, or the other way around, you need to perform a
"make distclean" in the root directory of the Redis distribution.

In case of build errors when trying to build a 32 bit binary of Redis, try
the following steps:

* Install the packages libc6-dev-i386 (also try g++-multilib).
* Try using the following command line instead of "make 32bit":

    make CFLAGS="-m32 -march=native" LDFLAGS="-m32"

Allocator
---------

Selecting a non-default memory allocator when building Redis is done by setting
the `MALLOC` environment variable. Redis is compiled and linked against libc
malloc by default, with the exception of jemalloc being the default on Linux
systems. This default was picked because jemalloc has proven to have fewer
fragmentation problems than libc malloc.

To force compiling against libc malloc, use:

    % make MALLOC=libc

To compile against jemalloc on Mac OS X systems, use:

    % make MALLOC=jemalloc

Verbose build
-------------

Redis will build with a user friendly colorized output by default.
If you want to see a more verbose output use the following:

    % make V=1

Running Redis
-------------

To run Redis with the default configuration just type:

    % cd src
    % ./redis-server
    
If you want to provide your redis.conf, you have to run it using an additional
parameter (the path of the configuration file):

    % cd src
    % ./redis-server /path/to/redis.conf

It is possible to alter the Redis configuration passing parameters directly
as options using the command line. Examples:

    % ./redis-server --port 9999 --slaveof 127.0.0.1 6379
    % ./redis-server /etc/redis/6379.conf --loglevel debug

All the options in redis.conf are also supported as options using the command
line, with exactly the same name.

Playing with Redis
------------------

You can use redis-cli to play with Redis. Start a redis-server instance,
then in another terminal try the following:

    % cd src
    % ./redis-cli
    redis> ping
    PONG
    redis> set foo bar
    OK
    redis> get foo
    "bar"
    redis> incr mycounter
    (integer) 1
    redis> incr mycounter
    (integer) 2
    redis> 

You can find the list of all the available commands here:

    http://redis.io/commands

Installing Redis
-----------------

In order to install Redis binaries into /usr/local/bin just use:

    % make install

You can use "make PREFIX=/some/other/directory install" if you wish to use a
different destination.

Make install will just install binaries in your system, but will not configure
init scripts and configuration files in the appropriate place. This is not
needed if you want just to play a bit with Redis, but if you are installing
it the proper way for a production system, we have a script doing this
for Ubuntu and Debian systems:

    % cd utils
    % ./install_server

The script will ask you a few questions and will setup everything you need
to run Redis properly as a background daemon that will start again on
system reboots.

You'll be able to stop and start Redis using the script named
/etc/init.d/redis_<portnumber>, for instance /etc/init.d/redis_6379.

Code contributions
---

Note: by contributing code to the Redis project in any form, including sending
a pull request via Github, a code fragment or patch via private email or
public discussion groups, you agree to release your code under the terms
of the BSD license that you can find in the COPYING file included in the Redis
source distribution.

Please see the CONTRIBUTING file in this source distribution for more
information.

Enjoy!

About

a test of embedding redis within a program - native rdb in memory access - very fast benchmarks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published