Repository navigation
feat: Batched Uploads and Green Threads - #14
Conversation
Breaks localtaskqueue. We can just have slow green threads instead.
nkemnitz
left a comment
There was a problem hiding this comment.
I can test this change along with my next test run once the tests are passing.
Splitting the features into separate PR's would help me speed up review and tests.
| try: | ||
| iter(obj) | ||
| if type(obj) is dict: | ||
| return [ obj ] |
There was a problem hiding this comment.
list(obj) does what you want, [obj] just puts the dictionary itself in a list.
There was a problem hiding this comment.
That's actually what I wanted for this case.
There was a problem hiding this comment.
Got it. If it's not a "general purpose" function, you could try to hide it a bit from the user - maybe name it _to_iterable. Not crucial, though.
| from .secrets import aws_credentials | ||
|
|
||
|
|
||
| def toiter(obj): |
There was a problem hiding this comment.
Would change the name to to_iterable - you are not returning an iterator.
There was a problem hiding this comment.
Now I am!
| AWS_BATCH_SIZE = 10 | ||
|
|
||
| resps = [] | ||
| for i in range(0, len(tasks), AWS_BATCH_SIZE): |
There was a problem hiding this comment.
Iterables are not guaranteed to have len (generators, for example)
There was a problem hiding this comment.
This is true and a headache. I should call it "tolist".
| def check_monkey_patch_status(self): | ||
| import gevent.monkey | ||
| if not gevent.monkey.is_module_patched("socket"): | ||
| print(yellow(""" |
e4c68fb to
b61a1e9
Compare
|
@nkemnitz latest changes include allowing the use of generators instead of lists in Generators are necessary for two reasons when the number of tasks being generated becomes large. Firstly, they allow the commencement of upload nearly instantly. Previously, while batching was an option, typically people would create lists of hundreds of thousands or millions of elements before submitting them for upload. This process took many seconds of time to complete, resulting in substantial latency. Secondly, these lists of millions of items would often result in MemoryErrors, requiring more complex batching logic. Now, so long as the user structures their submission logic as a generator, both issues are disposed of completely. |
|
|
||
| import taskqueue | ||
| from taskqueue import RegisteredTask, TaskQueue, MockTask, PrintTask, LocalTaskQueue, MockTaskQueue | ||
| from taskqueue import RegisteredTask, GreenTaskQueue, TaskQueue, MockTask, PrintTask, LocalTaskQueue, MockTaskQueue |
There was a problem hiding this comment.
No monkey patching here, so GreenTaskQueue will simply behave as a single threaded TaskQueue. monkey patching was disrupting LocalTaskQueue.
a840860 to
8d2482e
Compare
8d2482e to
f450e39
Compare
df58d58 to
eb688c7
Compare
eb688c7 to
3d752d8
Compare
8384f8a to
e06192c
Compare
e06192c to
4adf1f0
Compare
This contains a few features.
delay_secondsto insert and insert_all which allows you to delay a message's visibility in the queue.