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
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));
// setting the client-IP

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

Loading…
Cancel
Save