sjamesr / jfreesane

Java API to talk to the SANE scanning daemon
Apache License 2.0
60 stars 25 forks source link

Improve performance on consecutive write() calls. #18

Closed jeromebenois closed 9 years ago

jeromebenois commented 9 years ago

Hi,

Add tcp_no_delay on client socket improve network performance throughput between jfreesane client and sane.d server !

Cheers, Jérôme.

sjamesr commented 9 years ago

Hey Jerome,

Can you explain a bit more how this helps? I imagine it would have a slight impact on latency but a negative impact on bandwidth.

Thanks, James

jeromebenois commented 9 years ago

Thanks for your prompt feedback!

We use your excellent jfreesane library on our product and we have two deployment use cases :

We have investigated with Wireshark in order to understand important latency mesured on "set_option" exchange (rpc code=5). Each set_option consumes ~200ms with jfreesane and ~20ms with scanimage.

The main difference is scanimage use TCP_NO_DELAY=on. With this option we have a same latency with scanimage and jfreesane.

We have not found difference on network bandwith.

Cheers, Jérôme.

sjamesr commented 9 years ago

Excellent! I also tried it on my own setup and did see a big reduction in setOption latency. It does result in an increase in the number of transmitted packets (e.g. SaneSessionTest.setOptionValueSucceedsForString) went from 50 to 67. Not a big deal in today's high bandwidth networks I guess, but JFreeSane could be smarter in the way it generates requests to SANE (e.g. creating the request in an internal buffer and then writing the whole buffer at once).

sjamesr commented 9 years ago

Thanks for the contribution!