some enhancements to the access tracker (less synchronization)

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4812 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 17 years ago
parent 56a300f92a
commit 1127d62b64

@ -733,7 +733,7 @@ public final class httpd implements serverHandler {
// reseting the empty request counter // reseting the empty request counter
this.emptyRequestCount = 0; this.emptyRequestCount = 0;
// counting the amount of received requests within this permanent conneciton // counting the amount of received requests within this permanent connection
this.prop.setProperty(httpHeader.CONNECTION_PROP_KEEP_ALIVE_COUNT, Integer.toString(++this.keepAliveRequestCount)); this.prop.setProperty(httpHeader.CONNECTION_PROP_KEEP_ALIVE_COUNT, Integer.toString(++this.keepAliveRequestCount));
// setting the client-IP // setting the client-IP

@ -43,11 +43,11 @@ package de.anomic.server;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.ConcurrentModificationException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import de.anomic.server.logging.serverLog; import de.anomic.server.logging.serverLog;
@ -68,7 +68,7 @@ public abstract class serverAbstractSwitch<E> implements serverSwitch<E> {
private HashMap<InetAddress, String> authorization; private HashMap<InetAddress, String> authorization;
private TreeMap<String, serverBusyThread> workerThreads; private TreeMap<String, serverBusyThread> workerThreads;
private TreeMap<String, serverSwitchAction> switchActions; private TreeMap<String, serverSwitchAction> switchActions;
protected HashMap<String, TreeMap<Long, String>> accessTracker; // mappings from requesting host to an ArrayList of serverTrack-entries protected ConcurrentHashMap<String, TreeMap<Long, String>> accessTracker; // mappings from requesting host to an ArrayList of serverTrack-entries
private LinkedBlockingQueue<E> cacheStack; private LinkedBlockingQueue<E> cacheStack;
public serverAbstractSwitch(File rootPath, String initPath, String configPath, boolean applyPro) { public serverAbstractSwitch(File rootPath, String initPath, String configPath, boolean applyPro) {
@ -148,7 +148,7 @@ public abstract class serverAbstractSwitch<E> implements serverSwitch<E> {
// other settings // other settings
authorization = new HashMap<InetAddress, String>(); authorization = new HashMap<InetAddress, String>();
accessTracker = new HashMap<String, TreeMap<Long, String>>(); accessTracker = new ConcurrentHashMap<String, TreeMap<Long, String>>();
// init thread control // init thread control
workerThreads = new TreeMap<String, serverBusyThread>(); workerThreads = new TreeMap<String, serverBusyThread>();
@ -177,14 +177,10 @@ public abstract class serverAbstractSwitch<E> implements serverSwitch<E> {
if (accessPath == null) accessPath="NULL"; if (accessPath == null) accessPath="NULL";
TreeMap<Long, String> access = accessTracker.get(host); TreeMap<Long, String> access = accessTracker.get(host);
if (access == null) access = new TreeMap<Long, String>(); if (access == null) access = new TreeMap<Long, String>();
synchronized (access) { access.put(new Long(System.currentTimeMillis()), accessPath);
access.put(new Long(System.currentTimeMillis()), accessPath);
// write back to tracker // write back to tracker
try { accessTracker.put(host, clearTooOldAccess(access));
accessTracker.put(host, clearTooOldAccess(access));
} catch (ConcurrentModificationException e) {};
}
} }
public TreeMap<Long, String> accessTrack(String host) { public TreeMap<Long, String> accessTrack(String host) {
@ -192,20 +188,17 @@ public abstract class serverAbstractSwitch<E> implements serverSwitch<E> {
TreeMap<Long, String> access = accessTracker.get(host); TreeMap<Long, String> access = accessTracker.get(host);
if (access == null) return null; if (access == null) return null;
synchronized (access) { // clear too old entries
// clear too old entries if ((access = clearTooOldAccess(access)).size() != access.size()) {
int oldsize = access.size(); // write back to tracker
if ((access = clearTooOldAccess(access)).size() != oldsize) { if (access.size() == 0) {
// write back to tracker accessTracker.remove(host);
if (access.size() == 0) { } else {
accessTracker.remove(host); accessTracker.put(host, access);
} else {
accessTracker.put(host, access);
}
} }
return access;
} }
return access;
} }
private TreeMap<Long, String> clearTooOldAccess(TreeMap<Long, String> access) { private TreeMap<Long, String> clearTooOldAccess(TreeMap<Long, String> access) {
@ -215,9 +208,7 @@ public abstract class serverAbstractSwitch<E> implements serverSwitch<E> {
public Iterator<String> accessHosts() { public Iterator<String> accessHosts() {
// returns an iterator of hosts in tracker (String) // returns an iterator of hosts in tracker (String)
HashMap<String, TreeMap<Long, String>> accessTrackerClone = new HashMap<String, TreeMap<Long, String>>(); HashMap<String, TreeMap<Long, String>> accessTrackerClone = new HashMap<String, TreeMap<Long, String>>();
try { accessTrackerClone.putAll(accessTracker);
accessTrackerClone.putAll(accessTracker);
} catch (ConcurrentModificationException e) {}
return accessTrackerClone.keySet().iterator(); return accessTrackerClone.keySet().iterator();
} }

Loading…
Cancel
Save