Author: toad
Date: 2009-02-16 14:26:35 +0000 (Mon, 16 Feb 2009)
New Revision: 25660
Modified:
branches/db4o/freenet/src/freenet/support/compress/Compressor.java
branches/db4o/freenet/src/freenet/support/compress/RealCompressor.java
Log:
Move compression semaphore so it doesn't get stored or read
Modified: branches/db4o/freenet/src/freenet/support/compress/Compressor.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/compress/Compressor.java
2009-02-16 14:26:05 UTC (rev 25659)
+++ branches/db4o/freenet/src/freenet/support/compress/Compressor.java
2009-02-16 14:26:35 UTC (rev 25660)
@@ -53,32 +53,6 @@
return compressor.decompress(dbuf, i, j, output);
}
-
- public static final Semaphore compressorSemaphore = new
Semaphore(getMaxRunningCompressionThreads());
-
- private static int getMaxRunningCompressionThreads() {
- int maxRunningThreads = 1;
-
- String osName = System.getProperty("os.name");
- if(osName.indexOf("Windows") == -1 &&
(osName.toLowerCase().indexOf("mac os x") > 0) ||
(!NativeThread.usingNativeCode()))
- // OS/X niceness is really weak, so we don't
want any more background CPU load than necessary
- // Also, on non-Windows, we need the native
threads library to be working.
- maxRunningThreads = 1;
- else {
- // Most other OSs will have reasonable
niceness, so go by RAM.
- Runtime r = Runtime.getRuntime();
- int max = r.availableProcessors(); // FIXME
this may change in a VM, poll it
- long maxMemory = r.maxMemory();
- if(maxMemory < 128 * 1024 * 1024)
- max = 1;
- else
- // one compressor thread per (128MB of
ram + available core)
- max = Math.min(max, (int)
(Math.min(Integer.MAX_VALUE, maxMemory / (128 * 1024 * 1024))));
- maxRunningThreads = max;
- }
- Logger.minor(COMPRESSOR_TYPE.class, "Maximum Compressor
threads: " + maxRunningThreads);
- return maxRunningThreads;
- }
}
/**
Modified: branches/db4o/freenet/src/freenet/support/compress/RealCompressor.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/compress/RealCompressor.java
2009-02-16 14:26:05 UTC (rev 25659)
+++ branches/db4o/freenet/src/freenet/support/compress/RealCompressor.java
2009-02-16 14:26:35 UTC (rev 25660)
@@ -9,8 +9,10 @@
import freenet.support.Executor;
import freenet.support.Logger;
import freenet.support.OOMHandler;
+import freenet.support.compress.Compressor.COMPRESSOR_TYPE;
import freenet.support.io.NativeThread;
import java.util.LinkedList;
+import java.util.concurrent.Semaphore;
import com.db4o.ObjectContainer;
@@ -19,6 +21,7 @@
private final Executor exec;
private ClientContext context;
private static final LinkedList<CompressJob> _awaitingJobs = new
LinkedList<CompressJob>();
+ public static final Semaphore compressorSemaphore = new
Semaphore(getMaxRunningCompressionThreads());
public RealCompressor(Executor e) {
this.exec = e;
@@ -51,7 +54,7 @@
continue;
}
}
-
Compressor.COMPRESSOR_TYPE.compressorSemaphore.acquire();
+ compressorSemaphore.acquire();
} catch(InterruptedException e) {
Logger.error(this, "caught: "+e.getMessage(),
e);
continue;
@@ -82,7 +85,7 @@
} catch(Throwable t) {
Logger.error(this, "Caught " +
t + " in " + this, t);
} finally {
-
Compressor.COMPRESSOR_TYPE.compressorSemaphore.release();
+ compressorSemaphore.release();
}
}
@@ -98,4 +101,27 @@
return false;
}
+ private static int getMaxRunningCompressionThreads() {
+ int maxRunningThreads = 1;
+
+ String osName = System.getProperty("os.name");
+ if(osName.indexOf("Windows") == -1 &&
(osName.toLowerCase().indexOf("mac os x") > 0) ||
(!NativeThread.usingNativeCode()))
+ // OS/X niceness is really weak, so we don't want any
more background CPU load than necessary
+ // Also, on non-Windows, we need the native threads
library to be working.
+ maxRunningThreads = 1;
+ else {
+ // Most other OSs will have reasonable niceness, so go
by RAM.
+ Runtime r = Runtime.getRuntime();
+ int max = r.availableProcessors(); // FIXME this may
change in a VM, poll it
+ long maxMemory = r.maxMemory();
+ if(maxMemory < 128 * 1024 * 1024)
+ max = 1;
+ else
+ // one compressor thread per (128MB of ram +
available core)
+ max = Math.min(max, (int)
(Math.min(Integer.MAX_VALUE, maxMemory / (128 * 1024 * 1024))));
+ maxRunningThreads = max;
+ }
+ Logger.minor(RealCompressor.class, "Maximum Compressor threads:
" + maxRunningThreads);
+ return maxRunningThreads;
+ }
}
\ No newline at end of file
_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs