-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from insight-platform/mpmc
Implement mpmc queue
- Loading branch information
Showing
15 changed files
with
2,686 additions
and
144 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,58 @@ | ||
import time | ||
import os | ||
from rocksq import remove_mpmc_queue, StartPosition | ||
from rocksq.blocking import MpmcQueue | ||
|
||
NUM = 1 | ||
OPS = 1000 | ||
RELEASE_GIL = True | ||
PATH = '/tmp/mpmc-queue' | ||
TTL = 60 | ||
LABEL_ONE = 'label1' | ||
LABEL_TWO = 'label2' | ||
LABEL_THREE = 'label3' | ||
|
||
# if directory exists, remove it | ||
if os.path.exists(PATH): | ||
remove_mpmc_queue(PATH) | ||
|
||
q = MpmcQueue(PATH, TTL) | ||
|
||
start = time.time() | ||
for i in range(OPS): | ||
data = [bytes(str(i), 'utf-8')] | ||
q.add(data, no_gil=RELEASE_GIL) | ||
v = q.next(label=LABEL_ONE, start_position=StartPosition.Oldest, max_elements=NUM, no_gil=RELEASE_GIL) | ||
assert len(v) == NUM | ||
assert v == data | ||
|
||
end = time.time() | ||
|
||
print("Time taken: %f" % (end - start)) | ||
|
||
v = q.next(label=LABEL_ONE, start_position=StartPosition.Oldest, max_elements=NUM, no_gil=RELEASE_GIL) | ||
assert len(v) == 0 | ||
|
||
v = q.next(label=LABEL_TWO, start_position=StartPosition.Newest, max_elements=NUM, no_gil=RELEASE_GIL) | ||
assert len(v) == NUM | ||
assert v == [bytes(str(OPS-1), 'utf-8')] | ||
|
||
labels = q.labels | ||
assert len(labels) == 2 | ||
assert LABEL_ONE in labels | ||
assert LABEL_TWO in labels | ||
|
||
r = q.remove_label(LABEL_THREE) | ||
assert not r | ||
|
||
r = q.remove_label(LABEL_ONE) | ||
assert r | ||
|
||
labels = q.labels | ||
assert len(labels) == 1 | ||
assert LABEL_ONE not in labels | ||
assert LABEL_TWO in labels | ||
|
||
v = q.next(label=LABEL_ONE, start_position=StartPosition.Oldest, max_elements=NUM, no_gil=RELEASE_GIL) | ||
assert len(v) == NUM | ||
assert v == [bytes(str(0), 'utf-8')] |
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,31 @@ | ||
import time | ||
import os | ||
from rocksq import remove_mpmc_queue, StartPosition | ||
from rocksq.blocking import MpmcQueue | ||
|
||
NUM = 1 | ||
OPS = 1000 | ||
RELEASE_GIL = True | ||
PATH = '/tmp/mpmc-queue' | ||
TTL = 60 | ||
LABEL = 'label' | ||
|
||
# if directory exists, remove it | ||
if os.path.exists(PATH): | ||
remove_mpmc_queue(PATH) | ||
|
||
q = MpmcQueue(PATH, TTL) | ||
|
||
start = time.time() | ||
for i in range(OPS): | ||
data = [bytes(str(i), 'utf-8')] | ||
q.add(data, no_gil=RELEASE_GIL) | ||
|
||
for i in range(OPS): | ||
v = q.next(label=LABEL, start_position=StartPosition.Oldest, max_elements=NUM, no_gil=RELEASE_GIL) | ||
assert len(v) == NUM | ||
assert v == [bytes(str(i), 'utf-8')] | ||
|
||
end = time.time() | ||
|
||
print("Time taken: %f" % (end - start)) |
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,58 @@ | ||
import time | ||
import os | ||
from rocksq import remove_mpmc_queue, StartPosition | ||
from rocksq.nonblocking import MpmcQueue | ||
|
||
NUM = 1 | ||
OPS = 1000 | ||
RELEASE_GIL = True | ||
PATH = '/tmp/mpmc-queue' | ||
TTL = 60 | ||
LABEL_ONE = 'label1' | ||
LABEL_TWO = 'label2' | ||
LABEL_THREE = 'label3' | ||
|
||
# if directory exists, remove it | ||
if os.path.exists(PATH): | ||
remove_mpmc_queue(PATH) | ||
|
||
q = MpmcQueue(PATH, TTL) | ||
|
||
start = time.time() | ||
for i in range(OPS): | ||
data = [bytes(str(i), 'utf-8')] | ||
q.add(data, no_gil=RELEASE_GIL).get() | ||
v = q.next(label=LABEL_ONE, start_position=StartPosition.Oldest, max_elements=NUM, no_gil=RELEASE_GIL).get().data | ||
assert len(v) == NUM | ||
assert v == data | ||
|
||
end = time.time() | ||
|
||
print("Time taken: %f" % (end - start)) | ||
|
||
v = q.next(label=LABEL_ONE, start_position=StartPosition.Oldest, max_elements=NUM, no_gil=RELEASE_GIL).get().data | ||
assert len(v) == 0 | ||
|
||
v = q.next(label=LABEL_TWO, start_position=StartPosition.Newest, max_elements=NUM, no_gil=RELEASE_GIL).get().data | ||
assert len(v) == NUM | ||
assert v == [bytes(str(OPS-1), 'utf-8')] | ||
|
||
labels = q.labels.get().labels | ||
assert len(labels) == 2 | ||
assert LABEL_ONE in labels | ||
assert LABEL_TWO in labels | ||
|
||
r = q.remove_label(LABEL_THREE).get().removed_label | ||
assert not r | ||
|
||
r = q.remove_label(LABEL_ONE).get().removed_label | ||
assert r | ||
|
||
labels = q.labels.get().labels | ||
assert len(labels) == 1 | ||
assert LABEL_ONE not in labels | ||
assert LABEL_TWO in labels | ||
|
||
v = q.next(label=LABEL_ONE, start_position=StartPosition.Oldest, max_elements=NUM, no_gil=RELEASE_GIL).get().data | ||
assert len(v) == NUM | ||
assert v == [bytes(str(0), 'utf-8')] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
from enum import Enum | ||
|
||
def version() -> str: ... | ||
|
||
def remove_queue(queue_name: str): ... | ||
|
||
def remove_mpmc_queue(queue_name: str): ... | ||
|
||
class StartPosition(Enum): | ||
Oldest=0 | ||
Newest=1 |
Oops, something went wrong.