Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
energy
bmon
Commits
4ab50afd
Commit
4ab50afd
authored
Feb 05, 2015
by
Alan Mitchell
Browse files
Class to post sensor readings.
parent
46bde4fc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
1 deletion
+70
-1
bmsapp/scripts/performance_testing.py
bmsapp/scripts/performance_testing.py
+70
-1
No files found.
bmsapp/scripts/performance_testing.py
View file @
4ab50afd
...
...
@@ -4,6 +4,8 @@
import
threading
import
time
import
sys
import
datetime
import
random
import
json
import
yaml
...
...
@@ -53,5 +55,72 @@ def results_time():
return
tc
/
TRIES
,
load01
/
TRIES
,
load05
/
TRIES
,
load15
/
TRIES
,
dbsize
/
TRIES
class
ReadingPoster
(
threading
.
Thread
):
'''Posts sensor readings
'''
def
__init__
(
self
,
sensor_id
,
delay
=
0.0
):
"""
'sensor_id': the sensor_id to use in the post
'delay': delay between reading posts. Randomness is added
to cause delay to vary from 0 to 2 x 'delay'
The timestamp used in each post is random. The value is always 1.0.
"""
# run constructor of base class
threading
.
Thread
.
__init__
(
self
)
self
.
url
=
'https://bmon.ahfctest.webfactional.com/readingdb/reading/%s/store/'
%
sensor_id
self
.
delay
=
delay
# If only thing left running are daemon threads, Python will exit.
self
.
daemon
=
True
# controls whether thread continues to post
self
.
stop
=
False
# counts number of readings posted
self
.
reading_count
=
0
def
stop_posting
(
self
):
'''Call to stop thread from posting.
'''
self
.
stop
=
True
def
run
(
self
):
data
=
{
'storeKey'
:
'StorageKey'
,
'val'
:
1.0
}
dt_base
=
datetime
.
datetime
.
now
()
while
True
:
if
self
.
stop
:
return
# delay a random amount of time that averages to the requested delay.
time
.
sleep
(
self
.
delay
*
2.0
*
random
.
random
())
dt_new
=
dt_base
+
datetime
.
timedelta
(
seconds
=
random
.
random
()
*
1e7
)
data
[
'ts'
]
=
dt_new
.
strftime
(
'%Y-%m-%d %H:%M:%S'
)
requests
.
get
(
self
.
url
,
params
=
data
,
verify
=
False
)
self
.
reading_count
+=
1
if
__name__
==
'__main__'
:
print
results_time
()
#print results_time()
TOT_POST_TIME
=
5.0
# seconds
posters
=
[]
for
i
in
range
(
5
):
sensor_id
=
'test_%03d'
%
i
poster
=
ReadingPoster
(
sensor_id
,
0.0
)
posters
.
append
(
poster
)
poster
.
start
()
time
.
sleep
(
TOT_POST_TIME
)
total_reads
=
0
for
p
in
posters
:
p
.
stop_posting
()
total_reads
+=
p
.
reading_count
print
'%.1f posts / second'
%
(
total_reads
/
TOT_POST_TIME
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment