Skip to content

Instantly share code, notes, and snippets.

@bunelr

bunelr/README.md Secret

Last active December 19, 2019 10:24
Show Gist options
  • Save bunelr/7d0255a827e84dc28125 to your computer and use it in GitHub Desktop.
Save bunelr/7d0255a827e84dc28125 to your computer and use it in GitHub Desktop.
Dogstatsd Benchmark

20000 and 15000 samples are not reliable for with tags because there is some OOM kills that restart the process

{
"5000": {
"50000": "352488",
"5000": "67712",
"10000": "180608",
"75000": "349728",
"20000": "258436",
"1500": "30864",
"40000": "329240",
"2000": "48600",
"7500": "96064",
"100000": "326032",
"15000": "225960",
"100": "16988",
"500": "20640",
"1000": "30884"
},
"10000": {
"50000": "483064",
"5000": "100064",
"10000": "147148",
"75000": "532056",
"20000": "333144",
"1500": "41504",
"40000": "453416",
"2000": "49652",
"7500": "145704",
"100000": "594516",
"15000": "279024",
"100": "19268",
"500": "21988",
"1000": "26224"
},
"15000": {
"50000": "623680",
"5000": "68364",
"10000": "196484",
"75000": "689292",
"20000": "372736",
"1500": "42520",
"40000": "605812",
"2000": "37092",
"7500": "148592",
"100000": "763620",
"15000": "296160",
"100": "20584",
"500": "22852",
"1000": "26872"
},
"2000": {
"50000": "128724",
"5000": "71908",
"10000": "88956",
"75000": "173584",
"20000": "131380",
"1500": "39448",
"40000": "178584",
"2000": "34264",
"7500": "122616",
"100000": "189788",
"15000": "141952",
"100": "16476",
"500": "20256",
"1000": "24504"
},
"40000": {
"50000": "1006364",
"5000": "112692",
"10000": "227036",
"75000": "1463676",
"20000": "416032",
"1500": "49328",
"40000": "768868",
"2000": "55464",
"7500": "155940",
"15000": "319136",
"100": "29108",
"500": "28664",
"1000": "32092"
},
"1500": {
"50000": "114108",
"5000": "90132",
"10000": "122812",
"75000": "166060",
"20000": "156268",
"1500": "38252",
"40000": "153380",
"2000": "46948",
"7500": "67432",
"100000": "101024",
"15000": "103780",
"100": "16148",
"500": "20248",
"1000": "25044"
},
"7500": {
"50000": "399532",
"5000": "93840",
"10000": "198264",
"75000": "460208",
"20000": "313272",
"1500": "30468",
"40000": "393632",
"2000": "48216",
"7500": "159160",
"100000": "480812",
"15000": "251924",
"100": "17276",
"500": "24684",
"1000": "26168"
},
"20000": {
"50000": "702292",
"5000": "101128",
"10000": "218488",
"75000": "789412",
"20000": "382768",
"1500": "33380",
"40000": "643820",
"2000": "53948",
"7500": "164660",
"100000": "875532",
"15000": "308400",
"100": "20424",
"500": "27484",
"1000": "35956"
},
"100": {
"50000": "29876",
"5000": "23660",
"10000": "24176",
"75000": "24312",
"20000": "24360",
"1500": "29960",
"40000": "23784",
"2000": "24416",
"7500": "29788",
"100000": "23484",
"15000": "23352",
"100": "15836",
"500": "19804",
"1000": "24056"
},
"500": {
"50000": "85632",
"5000": "67640",
"10000": "85744",
"75000": "59028",
"20000": "58388",
"1500": "37952",
"40000": "59408",
"2000": "33900",
"7500": "87836",
"100000": "78076",
"15000": "58364",
"100": "16072",
"500": "20004",
"1000": "24192"
},
"1000": {
"50000": "81296",
"5000": "61532",
"10000": "127276",
"75000": "129252",
"20000": "116468",
"1500": "30128",
"40000": "120876",
"2000": "33780",
"7500": "67092",
"100000": "84044",
"15000": "83536",
"100": "16164",
"500": "20056",
"1000": "24796"
}
}
{
"5000": {
"50000": "135332",
"5000": "43800",
"10000": "57652",
"75000": "148492",
"20000": "96600",
"1500": "24360",
"40000": "112736",
"2000": "25348",
"7500": "47528",
"100000": "124064",
"15000": "79540",
"100": "17208",
"500": "18660",
"1000": "20280"
},
"10000": {
"50000": "202372",
"5000": "35892",
"10000": "58568",
"75000": "235388",
"20000": "123756",
"1500": "23116",
"40000": "187592",
"2000": "24856",
"7500": "52072",
"100000": "230388",
"15000": "97740",
"100": "17236",
"500": "18808",
"1000": "20820"
},
"15000": {
"50000": "242732",
"5000": "37536",
"10000": "60292",
"75000": "272720",
"20000": "125620",
"1500": "24408",
"40000": "242092",
"2000": "25740",
"7500": "50036",
"100000": "319896",
"15000": "79740",
"100": "16608",
"500": "18624",
"1000": "20616"
},
"2000": {
"50000": "60940",
"5000": "40308",
"10000": "47012",
"75000": "67656",
"20000": "61860",
"1500": "24052",
"40000": "58428",
"2000": "27240",
"7500": "45308",
"100000": "62820",
"15000": "56092",
"100": "17172",
"500": "18628",
"1000": "20804"
},
"40000": {
"50000": "336488",
"5000": "38800",
"10000": "66012",
"75000": "395156",
"20000": "145348",
"1500": "22800",
"40000": "280484",
"2000": "24828",
"7500": "52940",
"100000": "473956",
"15000": "96268",
"100": "16540",
"500": "18900",
"1000": "20260"
},
"1500": {
"50000": "52752",
"5000": "36796",
"10000": "47928",
"75000": "65492",
"20000": "55216",
"1500": "21908",
"40000": "60628",
"2000": "25088",
"7500": "48080",
"100000": "56800",
"15000": "54260",
"100": "17264",
"500": "18892",
"1000": "20908"
},
"7500": {
"50000": "178204",
"5000": "38276",
"10000": "57736",
"75000": "168804",
"20000": "92404",
"1500": "22852",
"40000": "160240",
"2000": "25216",
"7500": "50160",
"100000": "170864",
"15000": "79548",
"100": "17148",
"500": "18792",
"1000": "20772"
},
"20000": {
"50000": "304584",
"5000": "37256",
"10000": "64912",
"75000": "358480",
"20000": "134052",
"1500": "23088",
"40000": "252496",
"2000": "24892",
"7500": "51488",
"100000": "417480",
"15000": "103896",
"100": "16572",
"500": "18200",
"1000": "21508"
},
"100": {
"50000": "20396",
"5000": "20240",
"10000": "19160",
"75000": "19372",
"20000": "20576",
"1500": "20668",
"40000": "20600",
"2000": "21240",
"7500": "20112",
"100000": "20204",
"15000": "19004",
"100": "16972",
"500": "18664",
"1000": "20744"
},
"500": {
"50000": "33448",
"5000": "34688",
"10000": "41044",
"75000": "32748",
"20000": "34712",
"1500": "21976",
"40000": "34836",
"2000": "24900",
"7500": "35764",
"100000": "33064",
"15000": "40616",
"100": "16892",
"500": "18600",
"1000": "20552"
},
"1000": {
"50000": "45024",
"5000": "38816",
"10000": "43920",
"75000": "43756",
"20000": "45396",
"1500": "24040",
"40000": "43884",
"2000": "27520",
"7500": "40980",
"100000": "44136",
"15000": "44644",
"100": "17252",
"500": "18708",
"1000": "20296"
}
}
{
"5000": {
"50000": "504080",
"5000": "490012",
"10000": "448692",
"75000": "460448",
"15000": "426892",
"2000": "414620",
"40000": "424932",
"1500": "423556",
"7500": "437804",
"100000": "439884",
"20000": "432644",
"100": "204828",
"500": "377744",
"1000": "399568"
},
"10000": {
"50000": "700392",
"5000": "840456",
"10000": "688660",
"75000": "662804",
"15000": "785372",
"2000": "690608",
"40000": "703980",
"1500": "698968",
"7500": "703220",
"100000": "693588",
"20000": "730656",
"100": "195892",
"500": "570672",
"1000": "631564"
},
"15000": {
"50000": "1235388",
"5000": "1160412",
"10000": "1181544",
"75000": "1604264",
"15000": "1191972",
"2000": "995632",
"40000": "1232416",
"1500": "1049620",
"7500": "1238868",
"100000": "939488",
"20000": "1042976",
"100": "232584",
"500": "736504",
"1000": "388452"
},
"2000": {
"50000": "204948",
"5000": "233900",
"10000": "235848",
"75000": "232400",
"15000": "211268",
"2000": "206040",
"40000": "242212",
"1500": "196928",
"7500": "229876",
"100000": "230408",
"20000": "233392",
"100": "137076",
"500": "203912",
"1000": "233752"
},
"1500": {
"50000": "203248",
"5000": "197528",
"10000": "189164",
"75000": "184484",
"15000": "169352",
"2000": "176844",
"40000": "202104",
"1500": "194184",
"7500": "199156",
"100000": "199580",
"20000": "187924",
"100": "139068",
"500": "167108",
"1000": "196852"
},
"7500": {
"50000": "627224",
"5000": "600008",
"10000": "588500",
"75000": "593196",
"15000": "622544",
"2000": "597296",
"40000": "610580",
"1500": "570092",
"7500": "597452",
"100000": "626280",
"20000": "611264",
"100": "217512",
"500": "502964",
"1000": "547960"
},
"20000": {
"50000": "1135848",
"5000": "1163184",
"10000": "870392",
"75000": "728188",
"15000": "709240",
"1500": "1242228",
"40000": "815256",
"2000": "1495668",
"7500": "1486144",
"100000": "395200",
"20000": "392936",
"100": "235952",
"500": "1053104",
"1000": "944332"
},
"100": {
"50000": "25272",
"5000": "26252",
"10000": "32176",
"75000": "25408",
"15000": "25948",
"2000": "32676",
"40000": "32780",
"1500": "25388",
"7500": "33136",
"100000": "25116",
"20000": "33272",
"100": "24540",
"500": "31836",
"1000": "25420"
},
"500": {
"50000": "100528",
"5000": "95028",
"10000": "99884",
"75000": "67588",
"15000": "98408",
"2000": "92756",
"40000": "98564",
"1500": "99560",
"7500": "97856",
"100000": "100080",
"20000": "67920",
"100": "71528",
"500": "91088",
"1000": "97884"
},
"1000": {
"50000": "146856",
"5000": "158612",
"10000": "131092",
"75000": "145916",
"15000": "157448",
"2000": "138816",
"40000": "154592",
"1500": "159116",
"7500": "150340",
"100000": "154996",
"20000": "159364",
"100": "99152",
"500": "129732",
"1000": "151092"
}
}
import subprocess
from collections import defaultdict
import json
import time
import random
import threading
from statsd import statsd
count = 0
try:
with open("bench.json","r") as previous_bench:
results= json.load(previous_bench)
print "Loaded previously started benchmark"
print results
except Exception as e:
print e
results=defaultdict(dict)
if not results:
results = defaultdict(dict)
tags = []
#for i in range(1,100):
# tags.append("tag:"+str(i))
nb_of_samples_per_second = [100,500,1000,1500,2000,5000,7500,10000,15000,20000,40000]
nb_of_different_metric = [100,500,1000,1500,2000,5000,7500,10000,15000,20000,40000,50000,75000,100000]
def get_process_pid(user, process):
reply = subprocess.check_output(["ps -u {0} -f | grep {1}".format(user,process)],shell=True)
return reply.split()[1]
def get_memory_usage(pid):
ps_reply = subprocess.check_output(["ps -v -p{0}".format(pid)],shell=True)
ps_lines = ps_reply.split("\n")
columns_line = ps_lines[0]
value_line = ps_lines[1]
mem_index = columns_line.split().index("RSS")
mem_value = value_line.split()[mem_index]
return mem_value
def get_dogstatsd_memory_usage():
pid = get_process_pid("dd-agent","dogstatsd")
return get_memory_usage(pid)
def start_agent():
subprocess.call(["sudo", "service", "datadog-agent", "start"])
time.sleep(5)
def stop_agent():
subprocess.call(["sudo", "service", "datadog-agent", "stop"])
time.sleep(5)
def feed_data(nb_hist,nb_of_calls_per_second):
global count
second_done = threading.Event()
end_second = threading.Timer(1, lambda: second_done.set())
end_second.start()
for call_nb in range(nb_of_calls_per_second):
value = random.random()
statsd.gauge("benchmark_perf.metric"+ str(count % nb_hist), value, tags = random.sample(tags, 0))
count +=1
second_done.wait()
for nb_of_samples in nb_of_samples_per_second:
for nb_of_hist in nb_of_different_metric:
try:
results[unicode(nb_of_samples)][unicode(nb_of_hist)]
except KeyError:
print "New data-point - looking into it"
pass
else:
print "Already exist - skipping"
continue
should_feed_data = threading.Event()
feeding_timer = threading.Timer(300, lambda: should_feed_data.clear())
stop_agent()
start_agent()
should_feed_data.set()
feeding_timer.start()
while should_feed_data.is_set():
feed_data(nb_of_hist,nb_of_samples)
memory_usage = get_dogstatsd_memory_usage()
results[unicode(nb_of_samples)][unicode(nb_of_hist)] = memory_usage
with open("bench.json","w") as output_file:
json.dump(dict(results),output_file,indent =4)
import matplotlib.pyplot as plt
import json
files_to_open = ["bench.json.withtags", "bench.json.notags.gauge", "bench.json.notags"]
for file in files_to_open:
plt.figure(figsize=(15,5))
with open(file, "r") as bench_results:
results = json.load(bench_results)
plt.xlabel("nb of different metrics")
plt.ylabel("memory usage in kb")
for nb_of_samples in sorted(results.keys(),key=int,reverse=True):
abs = []
ord = []
for hist_nb, mem_value in results[nb_of_samples].items():
abs.append(int(hist_nb))
ord.append(int(mem_value))
ord = sorted(ord,key=lambda x:abs[ord.index(x)])
abs.sort()
plt.plot(abs, ord, label="{0} samples per second".format(int(nb_of_samples)))
lgd = plt.legend(bbox_to_anchor=(1, 1), loc="upper left")
plt.savefig(file+".png", bbox_extra_artists=(lgd,), bbox_inches='tight')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment