Update of /cvsroot/freenet/freenet/src/freenet/transport
In directory sc8-pr-cvs1:/tmp/cvs-serv28229/src/freenet/transport
Modified Files:
ListenSelectorLoop.java tcpConnection.java
Log Message:
6184:
LSL: check all serversockets, not just those selected. May be losing reads on
serversockets, described on devl.
tcpConn: use direct buffers. Pool them. Maybe pooling will help avoid situations like
described on devl (400M reported JVM heap, 800M reported by OS).
Index: ListenSelectorLoop.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/transport/ListenSelectorLoop.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ListenSelectorLoop.java 5 Sep 2003 16:08:52 -0000 1.18
+++ ListenSelectorLoop.java 9 Sep 2003 15:04:28 -0000 1.19
@@ -91,20 +91,20 @@
boolean success = true;
oomSleep = 1000;
try {
- Iterator i = currentSet.iterator();
+ Iterator i = sel.keys().iterator();
while (i.hasNext()) {
try {
- SelectionKey curKey = (SelectionKey)i.next();
- i.remove(); //yes I think its a good idea
- ServerSocketChannel sc = (ServerSocketChannel)curKey.channel();
- SocketChannel chan = null;
- NIOListener listener = (NIOListener)curKey.attachment();
- //drain the channel
- do {
- chan = sc.accept();
- if (chan!=null)
- listener.accept(chan.socket());
- }while(chan!=null);
+ SelectionKey curKey = (SelectionKey)i.next();
+ //i.remove(); //yes I think its a good idea //
reenable iff switch back to selectedKeys
+ ServerSocketChannel sc =
(ServerSocketChannel)curKey.channel();
+ SocketChannel chan = null;
+ NIOListener listener =
(NIOListener)curKey.attachment();
+ //drain the channel
+ do {
+ chan = sc.accept();
+ if (chan!=null)
+ listener.accept(chan.socket());
+ }while(chan!=null);
} catch (OutOfMemoryError e) {
System.gc();
System.runFinalization();
Index: tcpConnection.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/transport/tcpConnection.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- tcpConnection.java 4 Sep 2003 22:45:06 -0000 1.38
+++ tcpConnection.java 9 Sep 2003 15:04:28 -0000 1.39
@@ -7,6 +7,7 @@
import java.net.Socket;
import java.net.InetAddress;
import java.util.HashMap;
+import java.util.LinkedList;
import java.nio.*;
public final class tcpConnection extends Connection {
@@ -40,6 +41,10 @@
static WriteSelectorLoop wsl;
private static Bandwidth ibw = null;
private static Bandwidth obw = null;
+ private static boolean poolBuffers = true;
+ private static LinkedList bufferPool = new LinkedList();
+ private static boolean useDirectBuffers = true;
+ private static int BUFFER_SIZE = 16384;
private static final int streamBufferSize() {
return freenet.Core.streamBufferSize;
@@ -173,7 +178,21 @@
/** NIO related stuff***/
sock.getChannel().configureBlocking(false);
- accumulator = ByteBuffer.allocate(16*1024); //FIXME:hardcoded
+ if(poolBuffers) {
+ synchronized(bufferPool) {
+ if(!bufferPool.isEmpty()) {
+ accumulator = (ByteBuffer)(bufferPool.removeFirst());
+ } else {
+ accumulator = useDirectBuffers ?
+ ByteBuffer.allocateDirect(BUFFER_SIZE) :
+ ByteBuffer.allocate(BUFFER_SIZE);
+ }
+ }
+ } else {
+ accumulator = useDirectBuffers ?
+ ByteBuffer.allocateDirect(BUFFER_SIZE) :
+ ByteBuffer.allocate(BUFFER_SIZE);
+ }
accumulator.limit(0).position(0);
nioout = new NIOOutputStream(sock.getChannel(),this);
nioin = new NIOInputStream(accumulator,sock.getChannel(),this);
@@ -392,7 +411,8 @@
* i.e. position = 0, limit = end of bytes available ("flipped")
*/
public ByteBuffer getInputBuffer() {
- return accumulator;
+ if(closed) return null;
+ else return accumulator;
}
Exception closeException;
@@ -484,13 +504,18 @@
if(finalized) return;
finalized = true;
logInstances("Finalizing");
- if(!closed) Core.logger.log(this, "finalized without being closed!"+this,
Logger.NORMAL);
+ if(!closed) Core.logger.log(this, "finalized without being closed!"+this,
+ Logger.NORMAL);
+ // Accumulator will not be reused after closure
+ if(poolBuffers)
+ bufferPool.addLast(accumulator);
try {
close(true);
} catch (Throwable t) {
Core.logger.log(this, "Caught "+t+" closing "+this+" in finalize()", t,
Logger.NORMAL);
}
- if(!reallyClosed) Core.logger.log(this, "finalized without being
reallyClosed!: "+this, Logger.NORMAL);
+ if(!reallyClosed) Core.logger.log(this, "finalized without being
reallyClosed!: "+this,
+ Logger.NORMAL);
//profiling
//WARNING:remove before release
synchronized(profLock) {
@@ -503,11 +528,13 @@
}
public final InputStream getIn() {
- return in;
+ if(closed) return null;
+ else return in;
}
public final NIOInputStream getUnderlyingIn() {
- return nioin;
+ if(closed) return null;
+ else return nioin;
}
public final OutputStream getOut() {
_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs