Code Poetry
and Text Adventures

by catid posted (>30 days ago) 4:50pm Thu. Apr 19th 2012 PDT
I added a new send buffer allocator to LibCat to take advantage of allocation patterns during file transfer and other common packet exchanges.

For small sizes, the Windows allocator is fairly efficient.  However, for the size buffers used during file transfer (~1500 bytes), it starts getting slow.  To avoid allocating these larger buffers repeatedly, I added several slab allocators that re-use previous buffers after they complete sending.  Starting at 128 bytes up to 1500, a configurable number of slabs are initialized.  64, by default.  Allocation sizes are rounded up to the next slab size.

They each have a free and acquire list, which are protected by different locks.  The acquire and release operations are O(1) and releases are batched to reduce locking.  The separate locks reduce contention between acquire and free operations.  The large number of slabs reduces contention between allocating different sizes.

During some quick testing sending and receiving 50KB reliable test messages, only 3 allocations were required -- the vast majority of buffer allocation was avoided and was able to reuse the previous buffers instead!
last edit by catid edited (>30 days ago) 5:03pm Thu. Apr 19th 2012 PDT