Created
September 25, 2016 19:33
-
-
Save balloob/c364470d17c01615b763dd1772791d43 to your computer and use it in GitHub Desktop.
Stress test Home Assistant via the HTTP api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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