I am writing a server application. It accepts thousands of incoming socket connections, each sending and receiving messages.
Every time a message is received or sent over the socket, I used to allocate new byte[] buffers, then they are garbage collected:
byte[] receivingBuffer = new byte[bufferSize];
To improve the performance, I want to reuse the byte[] buffers. Shall I use ArrayPool or MemoryPool?
Or shall I create an ObjectPool of fixed-length byte[] buffers? For example, if the messages I send and receive never exceed 100 KB, then I create an ObjectPool of 100 KB byte[] buffers. Every time I need to send or receive a message, I get one of these buffers.
Did some research and testing. ArrayPool is the right thing to use and will dramatically increase performance.