diff options
| author | orbiter <orbiter@6c8d7289-2bf4-0310-a012-ef5d649a1542> | 2010-08-18 09:51:00 +0000 |
|---|---|---|
| committer | orbiter <orbiter@6c8d7289-2bf4-0310-a012-ef5d649a1542> | 2010-08-18 09:51:00 +0000 |
| commit | f616cdfce40ddfe3fcb49a4ff04528a6237a242d (patch) | |
| tree | f073257d6e4c0c3698336f0b99f349f1c641bff9 /htroot | |
| parent | 2f8ff8ec02f42ad3bf9098e79dc09bfd46e72c92 (diff) | |
better resistance of NetworkImage generation against heavy load
this is needed for the network image on the yacy.net home page
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7046 6c8d7289-2bf4-0310-a012-ef5d649a1542
Diffstat (limited to 'htroot')
| -rw-r--r-- | htroot/NetworkPicture.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/htroot/NetworkPicture.java b/htroot/NetworkPicture.java index 69d327a36..3d62a22f6 100644 --- a/htroot/NetworkPicture.java +++ b/htroot/NetworkPicture.java @@ -24,6 +24,8 @@ // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+import java.util.concurrent.Semaphore;
+
import de.anomic.http.server.RequestHeader;
import de.anomic.search.Switchboard;
import de.anomic.search.SwitchboardConstants;
@@ -35,7 +37,7 @@ import de.anomic.yacy.graphics.NetworkGraph; /** draw a picture of the yacy network */
public class NetworkPicture {
- private static final Object sync = new Object();
+ private static final Semaphore sync = new Semaphore(1);
private static EncodedImage buffer = null;
private static long lastAccessSeconds = 0;
@@ -48,7 +50,9 @@ public class NetworkPicture { //System.out.println("*** NetworkPicture: cache hit (1)");
return buffer;
}
- synchronized (sync) {
+ if (buffer != null && sync.availablePermits() == 0) return buffer;
+ try {
+ sync.acquire();
if (buffer != null && !authorized && timeSeconds - lastAccessSeconds < 2) {
//System.out.println("*** NetworkPicture: cache hit (2)");
return buffer;
@@ -89,6 +93,9 @@ public class NetworkPicture { if (maxCount > 10000) maxCount = 10000;
buffer = new EncodedImage(NetworkGraph.getNetworkPicture(sb.peers, 10000, width, height, passiveLimit, potentialLimit, maxCount, coronaangle, communicationTimeout, env.getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified"), env.getConfig("network.unit.description", "unspecified"), bgcolor).getImage(), "png");
lastAccessSeconds = System.currentTimeMillis() / 1000;
+ sync.release();
+ } catch (InterruptedException e) {
+ if (sync.availablePermits() == 0) sync.release();
}
return buffer;
}
|
