RRDtool (Round Robin Database) is a tool to store and graphically display time-series data (e.g., network bandwidth, temperature, system load). In monitoring systems, like Nagios, it's commonly used to store and display the history of the performance data provided by the monitoring system.
In large setups, however, RRDtool quickly runs into disk-I/O related problems. A common way to tackle those kinds of problems is the use of RAM disks to store the RRD files. However, this kind of (usually homebaked) approach is rather unflexible and error-prone. Starting with version 1.4, RRDtool ships the RRDtool Caching Daemon (RRDCacheD) which is trying to provide a powerful and generic solution to this problem.
This talk will give an introduction to the functionality and use of RRDCacheD. After providing a short overview over the underlying problems and a general introduction to the way this is tackled by RRDCacheD, the talk will describe the features of the caching daemon in more depth.
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
OSMC 2010 | RRDCacheD - how to escape the I/O hell by Sebastian Harl
1. RRDtool Caching Daemon
How to Escape the I/O Hell
Sebastian “tokkee” Harl
<tokkee@debian.org>
Debian RRDtool Team
OSMC 2010
October 6, 2010
2. About RRDCacheD?
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 2 / 36
RRDCacheD = RRDtool Caching Daemon
meant for large setups to solve I/O-related problems
In short:
1. “intercept” RRD updates
2. accumulate data
3. write accumulated data to disk at once
3. How to Escape the I/O Hell — Sebastian “tokkee” Harl — 3 / 36
Background: RRDtool internals
RRDCacheD – behind the scenes
Using RRDCacheD
Integration of RRDCacheD
Future directions
4. Background: basic idea of RRDtool
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 4 / 36
current values should be available with high resolution
older values are increasingly less interesting (→ overview over
large time-spans)
⇒ consolidate old data with increasing density
⇒ keep data using the round-robin method
5. RRD, RRA, PDP, CF, . . . WTF?
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 5 / 36
Quick overview over basic concepts of RRDtool:
RRD: Round Robin Database
DS: Data Source
RRA: Round Robin Archive
PDP: Primary Data Point
CF: Consolidation Function
→ AVERAGE, MINIMUM, MAXIMUM, . . .
CDP: Consolidated Data Point
6. Background: data storage
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 6 / 36
Primary Data Points (PDP)
1 2 3 4 5 6
step: interval of an PDP (seconds)
average value of all updates in one step form a PDP
heartbeat: maximum amount of time that may pass before
considering a value “unknown”
7. Background: consolidating data
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 7 / 36
Round Robin Archive (RRA)
1 2 3 4 5 6
. . .
consolidation functions: AVERAGE, MIN, MAX, LAST
xff (xfiles factor): maximum amount of unknown PDPs
allowed for a valid CDP
steps: number of PDPs
rows: number of CDPs
8. updates animated
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 8 / 36
RRD file.rrd
step = 300 s
RRA 0: 5 minutes-average
RRA 1: 10 minutes-average
RRA 2: 60 minutes-average
RRA 3: 60 minutes-maximum
current time: 45 minutes
Header
RRA 0
RRA 1
RRA 2
RRA 3
9. updates animated
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 8 / 36
RRD file.rrd
step = 300 s
RRA 0: 5 minutes-average
RRA 1: 10 minutes-average
RRA 2: 60 minutes-average
RRA 3: 60 minutes-maximum
current time: 50 minutes
Header
RRA 0
RRA 1
RRA 2
RRA 3
10. updates animated
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 8 / 36
RRD file.rrd
step = 300 s
RRA 0: 5 minutes-average
RRA 1: 10 minutes-average
RRA 2: 60 minutes-average
RRA 3: 60 minutes-maximum
current time: 55 minutes
Header
RRA 0
RRA 1
RRA 2
RRA 3
11. updates animated
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 8 / 36
RRD file.rrd
step = 300 s
RRA 0: 5 minutes-average
RRA 1: 10 minutes-average
RRA 2: 60 minutes-average
RRA 3: 60 minutes-maximum
current time: 60 minutes
Header
RRA 0
RRA 1
RRA 2
RRA 3
12. updates in detail
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 9 / 36
update algorithm (schematic):
1. read headers
2. foreach RRA to be updated:
seek
read data
seek
write back modified data
3. seek
4. read headers
5. seek
6. write headers
14. Problem: disk I/O
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 11 / 36
Problem: in large setups, hard-disks soon hit their limits
15. Problem: disk I/O
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 11 / 36
Problem: in large setups, hard-disks soon hit their limits
update usually modifies a single value (“double”, 8 bytes)
consolidation modifies multiple CDPs spread over the file
but: disk I/O is done in multiples of a page size (usually
4096 bytes)
in addition: lots of seeks necessary
disks are optimized for sequential access
. . .
page
16. Problem: disk I/O
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 12 / 36
source: http://collectd.org/wiki/index.php/Inside_the_RRDtool_plugin
17. Solutions so far
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 13 / 36
“ancient days”: tmpfs and manual synchronization
⇒ inflexible, error-prone, requires sync of lots of data
RRDtool 1.3: madvise/fadvise
→ no read-ahead; optimize file-system caching
⇒ still requires reading/writing of whole pages on update
⇒ accumulate updates and write multiple, sequential updates
at once
→ RRDCacheD (since RRDtool 1.4, October 2009)
18. How to Escape the I/O Hell — Sebastian “tokkee” Harl — 14 / 36
Background: RRDtool internals
RRDCacheD – behind the scenes
Using RRDCacheD
Integration of RRDCacheD
Future directions
19. RRDCacheD: basics
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 15 / 36
. . .
page
⇒ reading 1 page (e. g., 4096 Bytes); changing 8 bytes; writing
back 1 page basically has the same overhead as:
20. RRDCacheD: basics
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 15 / 36
. . .
page
⇒ reading 1 page (e. g., 4096 Bytes); changing 8 bytes; writing
back 1 page basically has the same overhead as:
. . .
page
. . . reading 1 page; changing multiple values; writing back 1 page
⇒ 4096 / 8 = 512 times more updates possible (in theory)
22. RRDCacheD: basics
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 16 / 36
diskRRDCacheD
x updates
“intercept” RRD updates
accumulate values
on timeout: write accumulated values to disk
23. RRDCacheD: basics
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 16 / 36
diskRRDCacheD journal
x updates
“intercept” RRD updates
accumulate values
on timeout: write accumulated values to disk
journal allows recovery after crash
flush writes back single value on request
24. RRDCacheD: implementation
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 17 / 36
searchtree
graphic c Florian “octo” Forster
25. RRDCacheD: implementation
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 17 / 36
searchtree
graphic c Florian “octo” Forster
26. RRDCacheD: implementation
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 17 / 36
searchtree
update-
queue
update-
thread
filesystem
graphic c Florian “octo” Forster
27. RRDCacheD: implementation
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 17 / 36
searchtree
update-
queue
flush-queue
update-
thread
filesystem
graphic c Florian “octo” Forster
28. RRDCacheD: implementation
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 18 / 36
Server
the actual caching daemon
access to the daemon using sockets:
UNIX Domain or TCP (IPv4 / IPv6)
→ communication using a text-based protocol
Client
implemented in librrd
connection handling
abstraction of the network protocol
29. RRDCacheD: parameters/features
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 19 / 36
owner of the UNIX sockets
man rrdcached; # ;-)
rrdcached
-s rrdcached
-m 0660
-l unix:/var/run/rrdcached.sock
-P FLUSH
-l 10.42.23.1
-j /var/lib/rrdcached/journal/ -F
-b /var/lib/rrdcached/db/ -B
-w 3600
-z 3600
-f 86400
30. RRDCacheD: parameters/features
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 19 / 36
file permissions of the UNIX sockets
man rrdcached; # ;-)
rrdcached
-s rrdcached
-m 0660
-l unix:/var/run/rrdcached.sock
-P FLUSH
-l 10.42.23.1
-j /var/lib/rrdcached/journal/ -F
-b /var/lib/rrdcached/db/ -B
-w 3600
-z 3600
-f 86400
31. RRDCacheD: parameters/features
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 19 / 36
UNIX socket
man rrdcached; # ;-)
rrdcached
-s rrdcached
-m 0660
-l unix:/var/run/rrdcached.sock
-P FLUSH
-l 10.42.23.1
-j /var/lib/rrdcached/journal/ -F
-b /var/lib/rrdcached/db/ -B
-w 3600
-z 3600
-f 86400
32. RRDCacheD: parameters/features
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 19 / 36
access control for sockets
man rrdcached; # ;-)
rrdcached
-s rrdcached
-m 0660
-l unix:/var/run/rrdcached.sock
-P FLUSH
-l 10.42.23.1
-j /var/lib/rrdcached/journal/ -F
-b /var/lib/rrdcached/db/ -B
-w 3600
-z 3600
-f 86400
33. RRDCacheD: parameters/features
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 19 / 36
TCP IPv4 socket
man rrdcached; # ;-)
rrdcached
-s rrdcached
-m 0660
-l unix:/var/run/rrdcached.sock
-P FLUSH
-l 10.42.23.1
-j /var/lib/rrdcached/journal/ -F
-b /var/lib/rrdcached/db/ -B
-w 3600
-z 3600
-f 86400
34. RRDCacheD: parameters/features
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 19 / 36
journal settings
man rrdcached; # ;-)
rrdcached
-s rrdcached
-m 0660
-l unix:/var/run/rrdcached.sock
-P FLUSH
-l 10.42.23.1
-j /var/lib/rrdcached/journal/ -F
-b /var/lib/rrdcached/db/ -B
-w 3600
-z 3600
-f 86400
35. RRDCacheD: parameters/features
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 19 / 36
base directory settings
man rrdcached; # ;-)
rrdcached
-s rrdcached
-m 0660
-l unix:/var/run/rrdcached.sock
-P FLUSH
-l 10.42.23.1
-j /var/lib/rrdcached/journal/ -F
-b /var/lib/rrdcached/db/ -B
-w 3600
-z 3600
-f 86400
36. RRDCacheD: parameters/features
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 19 / 36
timeout
man rrdcached; # ;-)
rrdcached
-s rrdcached
-m 0660
-l unix:/var/run/rrdcached.sock
-P FLUSH
-l 10.42.23.1
-j /var/lib/rrdcached/journal/ -F
-b /var/lib/rrdcached/db/ -B
-w 3600
-z 3600
-f 86400
37. RRDCacheD: parameters/features
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 19 / 36
delay
man rrdcached; # ;-)
rrdcached
-s rrdcached
-m 0660
-l unix:/var/run/rrdcached.sock
-P FLUSH
-l 10.42.23.1
-j /var/lib/rrdcached/journal/ -F
-b /var/lib/rrdcached/db/ -B
-w 3600
-z 3600
-f 86400
38. RRDCacheD: parameters/features
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 19 / 36
“garbage collection”
man rrdcached; # ;-)
rrdcached
-s rrdcached
-m 0660
-l unix:/var/run/rrdcached.sock
-P FLUSH
-l 10.42.23.1
-j /var/lib/rrdcached/journal/ -F
-b /var/lib/rrdcached/db/ -B
-w 3600
-z 3600
-f 86400
39. RRDCacheD: base directory
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 20 / 36
recommendation: /var/lib/rrdcached/db/
(default: /tmp/!)
command line file system
foo.rrd /var/lib/rrdcached/db/foo.rrd
foo/bar.rrd /var/lib/rrdcached/db/foo/bar.rrd
/tmp/foo.rrd /tmp/foo.rrd
rejected when using -B
40. How to Escape the I/O Hell — Sebastian “tokkee” Harl — 21 / 36
Background: RRDtool internals
RRDCacheD – behind the scenes
Using RRDCacheD
Integration of RRDCacheD
Future directions
41. Available commands
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 22 / 36
dump∗
fetch∗
flush
graph∗
graphv∗
info∗
last∗
lastupdate∗
update
xport∗
∗
no “native” implementation (yet?)
42. Using RRDCacheD
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 23 / 36
--daemon command line option
RRDCACHED ADDRESS environment variable
⇒ fully transparent integration
43. Using RRDCacheD
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 23 / 36
--daemon command line option
RRDCACHED ADDRESS environment variable
⇒ fully transparent integration
Caveats:
base directory settings
rrdupdate’s --template not supported
sufficient RAM needs to be available!
44. Using RRDCacheD
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 23 / 36
--daemon command line option
RRDCACHED ADDRESS environment variable
⇒ fully transparent integration
Caveats:
base directory settings
rrdupdate’s --template not supported
sufficient RAM needs to be available!
45. C API
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 24 / 36
i n t s t a t u s ;
char ∗ values [ ] = { ” 1234567890:42 ” , ” 1234567900:23 ” };
i n t values num = 2;
/∗ daemon address == NULL => use $RRDCACHED ADDRESS ∗/
s t a t u s = rrdc connect ( daemon address ) ;
i f ( s t a t u s ) {
f p r i n t f ( stderr , ”ERROR: %s n” , r r d g e t e r r o r ( ) ) ;
e x i t ( 1 ) ;
}
s t a t u s = rrdc update ( ” f i l e . r r d ” , values num , values ) ;
i f ( s t a t u s ) /∗ . . . ∗/ ;
46. Perl “API”
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 25 / 36
use RRDs ;
RRDs : : update ( ” f i l e . r r d ” , ”−−daemon” , $daemon address ,
” 1234567890:42 ” , ” 1234567900:23 ” ) ;
my $err = RRDs : : e r r o r ;
die ”ERROR: $ e r r ” i f $err ;
47. Network Protocol
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 26 / 36
text and line based
lines contain a command name and optional parameters
e. g., FLUSH foo.rrd
response includes status code and message
status < 0: error condition (details included on same line)
status ≥ 0: success; number of further lines returned
e. g., 0 Success
48. Network protocol: BATCH
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 27 / 36
batch processing of multiple commands
reduce number of calls to read and write
→ optimization for really large setups with high data rates
->: BATCH
<-: 0 Go ahead. End with dot ’.’ on its own line.
->: UPDATE x.rrd 1223661439:1:2:3
->: UPDATE y.rrd 1223661440:3:4:5
->: ...
->: .
<-: 2 Errors
<-: 1 <error message for 1. command>
<-: 12 <error message for 12. command>
49. Security considerations
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 28 / 36
RRDCacheD allows to limit acceptable commands per socket
all data arriving at a socket will be accepted
network traffic is unencrypted
daemon should run as unprivileged user
⇒ admin is responsible for security
e. g., dedicated (V)LAN, VPN, etc.
50. How to Escape the I/O Hell — Sebastian “tokkee” Harl — 29 / 36
Background: RRDtool internals
RRDCacheD – behind the scenes
Using RRDCacheD
Integration of RRDCacheD
Future directions
51. Integration in collectd
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 30 / 36
rrdcached Plugin
http://collectd.org/wiki/index.php/Plugin:RRDCacheD
since version 4.6 (02/2009)
LoadPlugin rrdcached
<Plugin rrdcached>
DaemonAddress "unix:/var/run/rrdcached.sock"
</Plugin>
52. Integration in Nagios
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 31 / 36
PNP4Nagios supports RRDCached since Version 0.4.11
http://www.pnp4nagios.org/pnp/rrdcached
http://www.semintelligent.com/blog/articles/40/
nagios-performance-tuning-early-lessons-learned-
lessons-shared-part-45-scalable-performance-data-
graphing
53. Integration in PNP4Nagios
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 32 / 36
process perfdata.cfg
RRD_DAEMON_OPTS = 127.0.0.1:8888
config local.php
$conf[’RRD_DAEMON_OPTS’] = ’127.0.0.1:8888’;
54. Integration in other software
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 33 / 36
Cacti:
http://binaryfury.wann.net/2010/01/
rrdcached-and-cacti-not-quite-there-yet/
https://lists.oetiker.ch/pipermail/rrd-developers/
2010-March/003664.html
Ganglia:
http://sourceforge.net/apps/trac/ganglia/wiki/
rrdcached_integration
Munin:
http://munin-monitoring.org/ticket/444
openNMS:
http://www.opennms.org/wiki/Rrdcached
55. How to Escape the I/O Hell — Sebastian “tokkee” Harl — 34 / 36
Background: RRDtool internals
RRDCacheD – behind the scenes
Using RRDCacheD
Integration of RRDCacheD
Future directions
56. Future directions
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 35 / 36
“Native” support for fetch und graph
First steps:
DEF:v1=path/to/example.rrd:value:AVERAGE:daemon=r2d2.example.org
→ graphing of distributed data (in trunk)
encryption
real authentication
redundant/high availability setups
57. Future directions
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 35 / 36
“Native” support for fetch und graph
First steps:
DEF:v1=path/to/example.rrd:value:AVERAGE:daemon=r2d2.example.org
→ graphing of distributed data (in trunk)
encryption
real authentication
redundant/high availability setups
It’s OpenSource! ... send patches! ;-)
58. How to Escape the I/O Hell
How to Escape the I/O Hell — Sebastian “tokkee” Harl — 36 / 36
Thanks for your attention!
Any questions?
contact:
Sebastian “tokkee” Harl
<tokkee@debian.org>