fast-serialization icon indicating copy to clipboard operation
fast-serialization copied to clipboard

Buffer using configurable ByteBuffer pool

Open carterkozak opened this issue 8 years ago • 5 comments

Hi,

I'd like to provide a pool of constant-sized byte-buffers rather than using cached byte-arrays that are less configurable and expensive to grow. This would allow me to reuse an existing buffer pool from something like a jetty ByteBufferPool where heap space isn't sitting idle while non-serialization tasks are executing.

Thanks!

carterkozak avatar May 26 '17 15:05 carterkozak

Any runtime costs assigned with that (regarding serialization) ? If its for ByteXX offheap stuff: Welcome ! if you target serialization related caches: careful, JIT's are magical but not that magical :)

RuedigerMoeller avatar May 26 '17 15:05 RuedigerMoeller

another issue to keep in mind is the need for synchronization that comes with such pools. Might play well in a single threaded benchmark, but can be devastating in a 10k concurrent connection WebSocket server ..

RuedigerMoeller avatar Jun 20 '17 10:06 RuedigerMoeller

Heavy concurrent usage is actually what I'm targeting here, serialized objects are written to a byte array in memory, that array is pooled using a ThreadLocal. I would like to write the serialized data asynchronously, which currently requires me to maintain another pool of buffers and copy data from the threadlocal buffer to a second location prior to dispatching the IO operation.

The ByteBuffer piece isn't quite as important to me, just the ability to control when buffers are checked out and returned. It would be great if buffers were constant sized, and we used several of them rather than growing a single bytearray in memory to fit the largest object we see.

carterkozak avatar Jun 23 '17 14:06 carterkozak

Hm can you provide a file example from source code ? afair im pooling byte arrays in serialization, or do you mean the (actually independent) offheap ByteSource* sub lib ?

RuedigerMoeller avatar Jun 23 '17 15:06 RuedigerMoeller

Oh gosh, I feel quite silly, sorry for bothering you! I just need to hold off calling FSTObjectOutput.resetForReUse until I'm done writing. You've thought of everything :-)

carterkozak avatar Jun 23 '17 16:06 carterkozak