Skip to content

Instantly share code, notes, and snippets.

@jmcarp
Created March 10, 2017 20:48
Show Gist options
  • Save jmcarp/fcda91ea7f5ad7a68f4d14aba2a78edb to your computer and use it in GitHub Desktop.
Save jmcarp/fcda91ea7f5ad7a68f4d14aba2a78edb to your computer and use it in GitHub Desktop.
kube-es-bench
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import time
import datetime
import joblib
from faker import Factory
from elasticsearch import Elasticsearch
fake = Factory.create()
es = Elasticsearch([os.getenv('ES_HOST')])
ndocs = 10000
def bench(offset=0):
t0 = time.time()
for idx in range(ndocs):
res = es.index(
index='bench',
doc_type='bench',
id=idx + offset,
body={
'text': fake.paragraph(nb_sentences=1000),
'timestamp': datetime.datetime.now(),
},
)
print(offset, res['created'])
print('inserted {} documents in {}'.format(ndocs, time.time() - t0))
if __name__ == "__main__":
es.indices.delete(index='bench', ignore=[400, 404])
joblib.Parallel(n_jobs=4, backend='threading')(joblib.delayed(bench)(offset) for offset in [0, 10000, 20000, 30000])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment