there's bunch of compressed data chunks has asynchronously deflated - without blocking or slowing down main thread in shape or form.
decompressed chunks used main thread decompressed.
currently this:
foreach (var chunkpair in compressedchunkdata) { var task = task.factory.startnew<chunk>(() => { var compressedbytes = convert.frombase64string(chunkpair.value); var chunk = decompress(compressedbytes); return chunk; }).continuewith((finishedtask) => { var chunk = finishedtask.result; taskfinishactions.enqueue(() => { chunk.postserialize(); document.chunks.add(chunkpair.key, chunk); }); }); } // time here 20ms has passed!!!
the problem seems hijack core mainthread running on, butchers performance.
is there way make taskfactory
have thread per core , context switch away mainthread in brief moments when mainthread blocked?
edit: foreach loop not part of code becomes slow, long there sizable amount of decompression tasks running, mainthread slows down significantly.
edit2: new data decompress arrive time, loop not ran once:
- lets have 250 items arriving in
compressedchunkdata
first - next frame have 10 items, next 12, next 0, next 2, etc.
you use custom taskscheduler
sets thread priority low value. windows schedules higher priority threads first.
maybe need put expiration date on tasks don't queue much. sounds have need low-latency processing. each task check first action whether scheduled more n seconds ago, , if yes exit immediately.
an alternative design producer/consumer scenario low-priority threads taking work. see no need given requirements it's more flexible solution. creating hundreds of tasks not problem. each task small in-memory data structure. task != threads.
Comments
Post a Comment