-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Push and pop commands in client are now thread-safe.
- Loading branch information
Showing
7 changed files
with
222 additions
and
37 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from turbomq import TurboClient | ||
from threading import Thread | ||
import time | ||
|
||
thread_count = 64 | ||
message_size = 512 | ||
message_count_per_thread = 25000 | ||
|
||
def send(count, size): | ||
c = TurboClient('tcp://127.0.0.1:33444') | ||
q = c.get_queue('stress') | ||
|
||
message = 'M' * size; | ||
|
||
for i in xrange(count): | ||
q.push('in', message) | ||
|
||
c = TurboClient('tcp://127.0.0.1:33444') | ||
q = c.get_queue('stress') | ||
|
||
|
||
start_time = time.time() | ||
threads = [] | ||
for i in xrange(thread_count): | ||
t = Thread(target=send, args=(message_count_per_thread, message_size)) | ||
t.start() | ||
threads.append(t) | ||
|
||
for t in threads: | ||
t.join() | ||
|
||
total_message_count = message_count_per_thread * thread_count | ||
elapsed_time = time.time() - start_time | ||
tps = total_message_count / elapsed_time | ||
|
||
print('TPS:{}'.format(tps)) | ||
|
||
q.push('in', 'shutdown-{}'.format(total_message_count)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from turbomq import TurboEngine | ||
from threading import Thread | ||
import time | ||
|
||
def process(engine): | ||
q = engine.get_queue('stress') | ||
total_bytes = 0 | ||
total_messages = 0 | ||
start_time = 0 | ||
unit = (1.0 / (1024 * 1024)) | ||
total_sent_messages = 0 | ||
|
||
while True: | ||
message = q.pop('in', 60) | ||
if message is not None: | ||
data = message.content | ||
if start_time == 0: | ||
start_time = time.time() | ||
if data.startswith('shutdown'): | ||
total_sent_messages = int(data.split('-')[1]) | ||
break | ||
total_messages += 1 | ||
total_bytes += len(data) | ||
|
||
elapsed_time = time.time() - start_time | ||
tps = total_messages / elapsed_time | ||
throughput = total_bytes / elapsed_time | ||
|
||
print('Total sent messages: {}'.format(total_sent_messages)) | ||
print('Total received messages: {}'.format(total_messages)) | ||
print('Error: {}\n'.format(total_sent_messages - total_messages)) | ||
|
||
print('Elapsed time: {:.3f}s'.format(elapsed_time)) | ||
print('Total transferred data: {:.1f} MB'.format(unit * total_bytes)) | ||
print('TPS: {:.0f} messages/second'.format(tps)) | ||
print('Throughput: {:.1f} mbps'.format(unit * throughput)) | ||
|
||
e = TurboEngine('tcp://127.0.0.1:33444') | ||
e.run() | ||
process(e) |
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
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
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
Oops, something went wrong.