Skip to content

Commit

Permalink
Avoid busy wait in bapm_server
Browse files Browse the repository at this point in the history
Queue.get is a blocking call; no need of checking if the queue is
non-empty in a loop.

https://docs.python.org/3/library/queue.html#queue.Queue.get
  • Loading branch information
sajith committed Jan 12, 2024
1 parent b65b5b2 commit 5958b93
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions bapm_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ def start_consumer(thread_queue, es):
t1.start()

while True:
if not thread_queue.empty():
data = thread_queue.get()
if is_json(data):
resp = es.index(index="measurement-index", id=MSG_ID, document=data)
print(resp["result"])
MSG_ID += 1
else:
logger.info("Received non-JSON data. Not saving to ElasticSearch.")
data = thread_queue.get()
if is_json(data):
resp = es.index(index="measurement-index", id=MSG_ID, document=data)
print(resp["result"])
MSG_ID += 1
else:
logger.info("Received non-JSON data. Not saving to ElasticSearch.")


def main():
Expand Down

0 comments on commit 5958b93

Please sign in to comment.