* Transports:

- Move from a single connection limit threshold (80%) to
        two (75% and 87%), and only start rejecting tunnels
        at the higher threshold, to increase build success
      - Move some limit methods from the transports to TransportImpl
      - Add limit methods with a threshold argument
This commit is contained in:
zzz
2009-07-11 17:00:46 +00:00
parent e5139113b1
commit 0b590763f3
9 changed files with 48 additions and 38 deletions

View File

@ -34,8 +34,8 @@ public abstract class CommSystemFacade implements Service {
public int countActivePeers() { return 0; } public int countActivePeers() { return 0; }
public int countActiveSendPeers() { return 0; } public int countActiveSendPeers() { return 0; }
public boolean haveInboundCapacity() { return true; } public boolean haveInboundCapacity(int pct) { return true; }
public boolean haveOutboundCapacity() { return true; } public boolean haveOutboundCapacity(int pct) { return true; }
public boolean haveHighOutboundCapacity() { return true; } public boolean haveHighOutboundCapacity() { return true; }
public List getMostRecentErrorMessages() { return Collections.EMPTY_LIST; } public List getMostRecentErrorMessages() { return Collections.EMPTY_LIST; }

View File

@ -70,9 +70,9 @@ public class CommSystemFacadeImpl extends CommSystemFacade {
@Override @Override
public int countActiveSendPeers() { return (_manager == null ? 0 : _manager.countActiveSendPeers()); } public int countActiveSendPeers() { return (_manager == null ? 0 : _manager.countActiveSendPeers()); }
@Override @Override
public boolean haveInboundCapacity() { return (_manager == null ? false : _manager.haveInboundCapacity()); } public boolean haveInboundCapacity(int pct) { return (_manager == null ? false : _manager.haveInboundCapacity(pct)); }
@Override @Override
public boolean haveOutboundCapacity() { return (_manager == null ? false : _manager.haveOutboundCapacity()); } public boolean haveOutboundCapacity(int pct) { return (_manager == null ? false : _manager.haveOutboundCapacity(pct)); }
@Override @Override
public boolean haveHighOutboundCapacity() { return (_manager == null ? false : _manager.haveHighOutboundCapacity()); } public boolean haveHighOutboundCapacity() { return (_manager == null ? false : _manager.haveHighOutboundCapacity()); }

View File

@ -44,10 +44,11 @@ public interface Transport {
public void setListener(TransportEventListener listener); public void setListener(TransportEventListener listener);
public String getStyle(); public String getStyle();
public int countPeers();
public int countActivePeers(); public int countActivePeers();
public int countActiveSendPeers(); public int countActiveSendPeers();
public boolean haveCapacity(); public boolean haveCapacity();
public boolean haveHighCapacity(); public boolean haveCapacity(int pct);
public Vector getClockSkews(); public Vector getClockSkews();
public List getMostRecentErrorMessages(); public List getMostRecentErrorMessages();

View File

@ -78,8 +78,13 @@ public abstract class TransportImpl implements Transport {
} }
/** /**
* How many peers can we talk to right now? * How many peers are we connected to?
* * For NTCP, this is the same as active,
* but SSU actually looks at idle time for countActivePeers()
*/
public int countPeers() { return countActivePeers(); }
/**
* How many peers active in the last few minutes?
*/ */
public int countActivePeers() { return 0; } public int countActivePeers() { return 0; }
/** /**
@ -112,10 +117,18 @@ public abstract class TransportImpl implements Transport {
return _context.getProperty("i2np." + style + ".maxConnections", def); return _context.getProperty("i2np." + style + ".maxConnections", def);
} }
private static final int DEFAULT_CAPACITY_PCT = 75;
/** /**
* Can we initiate or accept a connection to another peer, saving some margin * Can we initiate or accept a connection to another peer, saving some margin
*/ */
public boolean haveCapacity() { return true; } public boolean haveCapacity() {
return haveCapacity(DEFAULT_CAPACITY_PCT);
}
/** @param pct are we under x% 0-100 */
public boolean haveCapacity(int pct) {
return countPeers() < getMaxConnections() * pct / 100;
}
/** /**
* Return our peer clock skews on a transport. * Return our peer clock skews on a transport.

View File

@ -206,15 +206,18 @@ public class TransportManager implements TransportEventListener {
/** /**
* Is at least one transport below its outbound connection limit + some margin * Is at least one transport below its outbound connection limit + some margin
* Use for throttling in the router. * Use for throttling in the router.
*
* @param pct percent of limit 0-100
*/ */
public boolean haveOutboundCapacity() { public boolean haveOutboundCapacity(int pct) {
for (int i = 0; i < _transports.size(); i++) { for (int i = 0; i < _transports.size(); i++) {
if (((Transport)_transports.get(i)).haveCapacity()) if (((Transport)_transports.get(i)).haveCapacity(pct))
return true; return true;
} }
return false; return false;
} }
private static final int HIGH_CAPACITY_PCT = 50;
/** /**
* Are all transports well below their outbound connection limit * Are all transports well below their outbound connection limit
* Use for throttling in the router. * Use for throttling in the router.
@ -223,7 +226,7 @@ public class TransportManager implements TransportEventListener {
if (_transports.size() <= 0) if (_transports.size() <= 0)
return false; return false;
for (int i = 0; i < _transports.size(); i++) { for (int i = 0; i < _transports.size(); i++) {
if (!((Transport)_transports.get(i)).haveHighCapacity()) if (!((Transport)_transports.get(i)).haveCapacity(HIGH_CAPACITY_PCT))
return false; return false;
} }
return true; return true;
@ -232,10 +235,12 @@ public class TransportManager implements TransportEventListener {
/** /**
* Is at least one transport below its inbound connection limit + some margin * Is at least one transport below its inbound connection limit + some margin
* Use for throttling in the router. * Use for throttling in the router.
*
* @param pct percent of limit 0-100
*/ */
public boolean haveInboundCapacity() { public boolean haveInboundCapacity(int pct) {
for (int i = 0; i < _transports.size(); i++) { for (int i = 0; i < _transports.size(); i++) {
if (_transports.get(i).getCurrentAddress() != null && _transports.get(i).haveCapacity()) if (_transports.get(i).getCurrentAddress() != null && _transports.get(i).haveCapacity(pct))
return true; return true;
} }
return false; return false;

View File

@ -321,15 +321,6 @@ public class NTCPTransport extends TransportImpl {
return countActivePeers() < getMaxConnections(); return countActivePeers() < getMaxConnections();
} }
@Override
public boolean haveCapacity() {
return countActivePeers() < getMaxConnections() * 4 / 5;
}
public boolean haveHighCapacity() {
return countActivePeers() < getMaxConnections() / 2;
}
/** queue up afterSend call, which can take some time w/ jobs, etc */ /** queue up afterSend call, which can take some time w/ jobs, etc */
void sendComplete(OutNetMessage msg) { _finisher.add(msg); } void sendComplete(OutNetMessage msg) { _finisher.add(msg); }

View File

@ -1334,6 +1334,13 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
super.afterSend(m, true); super.afterSend(m, true);
} }
@Override
public int countPeers() {
synchronized (_peersByIdent) {
return _peersByIdent.size();
}
}
@Override @Override
public int countActivePeers() { public int countActivePeers() {
long now = _context.clock().now(); long now = _context.clock().now();
@ -1379,19 +1386,6 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
} }
} }
@Override
public boolean haveCapacity() {
synchronized (_peersByIdent) {
return _peersByIdent.size() < getMaxConnections() * 4 / 5;
}
}
public boolean haveHighCapacity() {
synchronized (_peersByIdent) {
return _peersByIdent.size() < getMaxConnections() / 2;
}
}
/** /**
* Return our peer clock skews on this transport. * Return our peer clock skews on this transport.
* Vector composed of Long, each element representing a peer skew in seconds. * Vector composed of Long, each element representing a peer skew in seconds.

View File

@ -253,6 +253,12 @@ public class TunnelDispatcher implements Service {
return _participatingConfig.size(); return _participatingConfig.size();
} }
/******* may be used for congestion control later...
public int getParticipatingInboundGatewayCount() {
return _inboundGateways.size();
}
*******/
/** what is the date/time on which the last non-locally-created tunnel expires? */ /** what is the date/time on which the last non-locally-created tunnel expires? */
public long getLastParticipatingExpiration() { return _lastParticipatingExpiration; } public long getLastParticipatingExpiration() { return _lastParticipatingExpiration; }

View File

@ -510,8 +510,8 @@ class BuildHandler {
* reject this request. * reject this request.
*/ */
if (response == 0 && if (response == 0 &&
((isInGW && ! _context.commSystem().haveInboundCapacity()) || ((isInGW && ! _context.commSystem().haveInboundCapacity(87)) ||
(isOutEnd && ! _context.commSystem().haveOutboundCapacity()))) { (isOutEnd && ! _context.commSystem().haveOutboundCapacity(87)))) {
_context.throttle().setTunnelStatus("Rejecting tunnels: Connection limit"); _context.throttle().setTunnelStatus("Rejecting tunnels: Connection limit");
response = TunnelHistory.TUNNEL_REJECT_BANDWIDTH; response = TunnelHistory.TUNNEL_REJECT_BANDWIDTH;
} }
@ -574,7 +574,7 @@ class BuildHandler {
// just drop it. // just drop it.
if (response != 0 && if (response != 0 &&
(! _context.routerHash().equals(nextPeer)) && (! _context.routerHash().equals(nextPeer)) &&
(! _context.commSystem().haveOutboundCapacity()) && (! _context.commSystem().haveOutboundCapacity(75)) &&
(! _context.commSystem().isEstablished(nextPeer))) { (! _context.commSystem().isEstablished(nextPeer))) {
_context.statManager().addRateData("tunnel.dropConnLimits", 1, 0); _context.statManager().addRateData("tunnel.dropConnLimits", 1, 0);
return; return;