i2ptunnel uses un-buffered socket streams
Opened 9 years ago
Last modified 8 years ago
#666assignedenhancement
i2ptunnel uses un-buffered socket streams
Reported by:Zlatin BalevskyOwned by:sponge Priority: trivial Milestone:
Component: apps/i2ptunnel Version: 0.9 Keywords: performance profiling Cc:
Parent Tickets:
Sensitive: no
Description
When using SocketInputStream? every read, even if it's for a single byte will issue a system call. This can increase cpu usage a lot.
KillYourTV profiled his busy router with jvisualvm and looking through the results here http://killyourtv.i2p/tmp/zab/1342955097788.nps.gz
One of the low-hanging fruits that can be picked without side effects is suggested below. I'm not wrapping the output stream because that can have side-effects of delaying small writes.
#
# old_revision [0c106e0035abfbeb930e77608666b9ce971d152d]
#
# patch "apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelRunner.java"
# from [8e4c0e7830ef6086e24779a7cd43dcde95b87276]
# to [d0dccc96cb89e49d065bf691ca063854d09316e0]
#
============================================================
--- apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelRunner.java 8e4c0e7830ef6086e24779a7cd43dcde95b87276
+++ apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelRunner.java d0dccc96cb89e49d065bf691ca063854d09316e0
@@ -3,6 +3,7 @@ package net.i2p.i2ptunnel;
*/
package net.i2p.i2ptunnel;
+import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
@@ -130,7 +131,7 @@ public class I2PTunnelRunner extends I2P
return startedOn;
}
- protected InputStream getSocketIn() throws IOException { return s.getInputStream(); }
+ protected InputStream getSocketIn() throws IOException { return new BufferedInputStream(s.getInputStream()); }
protected OutputStream getSocketOut() throws IOException { return s.getOutputStream(); }
@Override