Skip to content

Instantly share code, notes, and snippets.

@balloob
Created September 25, 2016 19:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balloob/c364470d17c01615b763dd1772791d43 to your computer and use it in GitHub Desktop.
Save balloob/c364470d17c01615b763dd1772791d43 to your computer and use it in GitHub Desktop.
Stress test Home Assistant via the HTTP api
from multiprocessing.dummy import Pool
import sys
import time
from homeassistant import remote
# Docs: remote.API(host, [password], [port], [use_ssl])
api = remote.API('127.0.0.1')
start_time = time.time()
if len(sys.argv) < 2:
amount = 1000
else:
amount = int(sys.argv[1])
def job(i):
remote.set_state(api, 'kraken.test', 'Run {}'.format(i))
if i % 100 == 0:
print('.', end='', flush=True)
pool = Pool(10)
try:
pool.map(job, range(amount))
except KeyboardInterrupt:
pass
print()
print("--- Set {} states in {:.2f} seconds ---".format(
amount, time.time() - start_time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment