I am developing a provider application and from some tests that I have done, it seems that writing to the same channel from multiple threads gives lower throughput than using just only one thread to call Channel.write().
Also, from the upajProvPerf source code, it uses only one thread to write to a channel and even though we can increase the number of threads via the ‘-threads’ option, more threads seems to be used to handle more connections/channels rather than to improve write speed/throughput.
Is the best practice to write to a channel is to call Channel.write() from a single thread?
Yes, performance is best when writing from a single thread. Multiple threads result in lock contention while writing and slow things down.
The lock is applied on a per channel basis. You can use one thread per channel each with a single thread for multiple threads.