← Back to team overview

graphite-dev team mailing list archive

Re: [Question #121579]: Graphite Backend connections and volume

 

Question #121579 on Graphite changed:
https://answers.launchpad.net/graphite/+question/121579

chrismd posted a new comment:
Sorry, I promise I will document this soon. Here's the 2-minute version:

import socket
import struct
import cPickle

sock = socket.socket()
sock.connect( ('graphite-server', 2004) ) # pickle protocol is done on port 2004

data = gather_me_some_data()
# where data = [ (metic, datapoints), ... ]
# and datapoints = [ (timestamp, value), ... ]

serialized_data = cPickle.dumps(data, protocol=-1)
length_prefix = struct.pack("!L", len(serialized_data))
message = length_prefix + serialized_data
sock.sendall(message)

A brief note on efficiency. In general the larger each message is (the
more metrics/datapoints in each call to cPickle.dumps) the less
deserialization overhead is incurred by carbon, but messages cannot
exceed 1 meg (beyond that weird buffering issues hurt performance), so I
usually send about 500 datapoints per message.

-- 
You received this question notification because you are a member of
graphite-dev, which is an answer contact for Graphite.