fast-serialization
fast-serialization copied to clipboard
Buffer using configurable ByteBuffer pool
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!
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 :)
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 ..
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.
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 ?
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 :-)