summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorKristofer Hallin <kristofer@sunet.se>2021-10-07 17:15:09 +0200
committerKristofer Hallin <kristofer@sunet.se>2021-10-07 17:15:09 +0200
commitc440b456c95a934078eb46ff809e249393eaec00 (patch)
tree47519d98adeabd8af9bd780a0401fe9f4b691bd9 /tools
parentb3fe63802edc019e8a861d3c6ab51e5ec2f3570c (diff)
Better threading.
Diffstat (limited to 'tools')
-rw-r--r--tools/feeder.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/tools/feeder.py b/tools/feeder.py
index de61ee2..bc3c37e 100644
--- a/tools/feeder.py
+++ b/tools/feeder.py
@@ -5,7 +5,7 @@ import ipaddress
import datetime
import itertools
import json
-import multiprocessing.dummy as mp
+import threading
data = {
"ip": "",
@@ -28,11 +28,13 @@ data = {
def random_ipv4():
randint = random.randint(1, 0xffffffff)
+
return str(ipaddress.IPv4Address(randint))
def random_ipv6():
randint = random.randint(0, 2**128-1)
+
return str(ipaddress.IPv6Address(randint))
@@ -42,6 +44,7 @@ def random_port():
def random_asn():
randint = random.randint(1, 65536)
+
return f'AS{randint}'
@@ -116,6 +119,7 @@ def random_tld():
def get_timestamp():
utc_datetime = datetime.datetime.utcnow()
+
return utc_datetime.strftime("%Y-%m-%dT%H:%M:%SUTC")
@@ -159,17 +163,18 @@ def generate_blob():
return blob
-def send_blob(url):
+def send_blob():
+ url = 'http://localhost:8000/sc/v0/add'
+
+ print("Thread started")
try:
for i in range(1200):
requests.post(url, json=generate_blob())
+ print("Blob sent.")
except Exception:
print('Failed to send blob.')
if __name__ == '__main__':
- threads = mp.Pool(8)
-
- threads.map(send_blob, ['http://localhost:8000/sc/v0/add'])
- threads.close()
- threads.join()
+ for _ in range(0, 7):
+ threading.Thread(target=lambda: send_blob()).start()