Skip to content

Instantly share code, notes, and snippets.

View antirez's full-sized avatar

Salvatore Sanfilippo antirez

View GitHub Profile
./redis-stat vmpage samplesize 10000
Sampling 10000 random keys from DB 0...
Average serialized value size is: 12
Simulate fragmentation with different page sizes
8: bytes per page: 4.75, space efficiency: 59.38%
16: bytes per page: 10.18, space efficiency: 63.60%
32: bytes per page: 12.10, space efficiency: 37.81%
64: bytes per page: 12.05, space efficiency: 18.83%
128: bytes per page: 12.06, space efficiency: 9.43%
256: bytes per page: 12.09, space efficiency: 4.72%
/* The following is a simple program to check for memory corrections in
* DRAM with ECC switched off. Accordingly to recend large scale studies
* such as http://www.cs.toronto.edu/~bianca/papers/sigmetrics09.pdf
* the error rate is of 25,000-75,000 errors per billion hours per Mbit.
*
* If this is true you should see at least one error after a few days
* running this program at max in a computer without ECC.
*
* Compile with: gcc -O2 -Wall -W -o dramerr dramerr.c
*
./redis-stat ondisk-size
Sampling 10000 random keys from DB 0...
Average: 221
Standard deviation: 118.03
<= 1 | (0.00%)
<= 2 | (0.00%)
<= 4 | (0.67%)
<= 8 | (0.62%)
<= 16 |-- (1.84%)
require 'rubygems'
require 'redis'
r = Redis.new
(0..100000).each{|i|
["name","surname","age","sex","password"].each{|field|
if false
r.set("obj#{i}#{field}","foo")
else
r.hset("obj#{i}",field,"foo")
# We want to create our new object, and make sure it is in the Set of existing objects.
1) INCR object.nextid => 1000 # Get an unique ID for the next object
2) SET object:1000 "my object value" # Set the value of the object
3) SADD all.my.objects 1000 # Add the ID of the object to the target Set, representing all the objects
What happens if the client dies between 2 and 3? We have the object key, but "leaked" it forever as it's no longer in Set of our objects.
MULTI/EXEC fix this problem:
1) INCR object:nextid => 1000
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char *a = malloc(32);
char *b = malloc(45);
printf("a: %p\n", a);
free(a);
printf("b: %p\n", b);
set numclients 50
set ::reads 0
for {set i 0} {$i < $numclients} {incr i} {
set fd [socket 127.0.0.1 6379]
fconfigure $fd -translation binary -blocking 0
set ::client($i) $fd
puts -nonewline $fd "SUBSCRIBE foo\r\n"
flush $fd
fileevent $fd readable [list discardData $fd]
antirez@metal:/tmp$ ./a.out
allocated: 0 GB, fork() took 0.000
allocated: 1 GB, fork() took 0.016
allocated: 2 GB, fork() took 0.031
allocated: 3 GB, fork() took 0.046
allocated: 4 GB, fork() took 0.058
allocated: 5 GB, fork() took 0.072
allocated: 6 GB, fork() took 0.084
allocated: 7 GB, fork() took 0.095
allocated: 8 GB, fork() took 0.107
BEFORE:
redis> set foo "hello world"
Wrong number of arguments for 'set'
$ cat /bin/ls | ./redis-cli set x
OK
$ ./redis-cli
redis> substr x 0 1023
ELF>�&@@0�@8 @@@@@@�88@8@@@T�T� ��a�aP���a�TT@T@DDP�td0�0�A0�AttQ�tR�td��a�a >k2KQM$E81B[aO._Ph)Z-!G,`J 7TRmGNUd�k{�L�:ٔ�I�E^�&�aoNc W\*fbel3FSjY^]DCX
+1272564958.791616 (db 9) "hset" "smallhash" "tmp" 17179869184
+1272564958.791717 (db 9) "hset" "bighash" "tmp" 17179869184
+1272564958.791818 (db 9) "hincrby" "smallhash" "tmp" "17179869184"
+1272564958.791981 (db 9) "hincrby" "bighash" "tmp" "17179869184"
+1272564958.792238 (db 9) "hset" "smallhash" "tmp" " 11 "
+1272564958.792388 (db 9) "hset" "bighash" "tmp" " 11 "
+1272564958.792546 (db 9) "hincrby" "smallhash" "tmp" "1"
+1272564958.792784 (db 9) "hincrby" "bighash" "tmp" "1"
+1272564958.793034 (db 9) "set" "x" "foobar"
+1272564958.793285 (db 9) "expire" "x" "5"