Tunnels: Make new tunnel selection round-robin

Remove one-second stickiness, as OCMOSJ caching does the job better
http://zzz.i2p/topics/2454
This commit is contained in:
zzz
2020-03-24 12:33:29 +00:00
parent 5c1700c2ab
commit 7654a0af42
3 changed files with 18 additions and 41 deletions

View File

@ -1,3 +1,15 @@
2020-03-24 zzz
* Tunnels: Make new tunnel selection round-robin
2020-03-20 zzz
* Tunnels: FragmentHandler cleanup (ticket #2699)
2020-03-17 zzz
* i2psnark: Hide non-i2p trackers on details page
2020-03-15 zzz
* Ratchet: Stub out ack and ack request blocks
2020-03-01 zzz 2020-03-01 zzz
* Console: * Console:
- Disable browser launch on /configclients when a service - Disable browser launch on /configclients when a service

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */ /** deprecated */
public final static String ID = "Monotone"; public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION; public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 3; public final static long BUILD = 4;
/** for example "-test" */ /** for example "-test" */
public final static String EXTRA = ""; public final static String EXTRA = "";

View File

@ -40,8 +40,7 @@ public class TunnelPool {
private final TunnelPoolManager _manager; private final TunnelPoolManager _manager;
protected volatile boolean _alive; protected volatile boolean _alive;
private long _lifetimeProcessed; private long _lifetimeProcessed;
private TunnelInfo _lastSelected; private int _lastSelectedIdx;
private long _lastSelectionPeriod;
private final int _expireSkew; private final int _expireSkew;
private long _started; private long _started;
private long _lastRateUpdate; private long _lastRateUpdate;
@ -124,8 +123,6 @@ public class TunnelPool {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
_log.warn(toString() + ": Shutdown called"); _log.warn(toString() + ": Shutdown called");
_alive = false; _alive = false;
_lastSelectionPeriod = 0;
_lastSelected = null;
_context.statManager().removeRateStat(_rateName); _context.statManager().removeRateStat(_rateName);
synchronized (_inProgress) { synchronized (_inProgress) {
_inProgress.clear(); _inProgress.clear();
@ -152,20 +149,6 @@ public class TunnelPool {
_settings.readFromProperties(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY, props); _settings.readFromProperties(TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY, props);
} }
/**
* when selecting tunnels, stick with the same one for a brief
* period to allow batching if we can.
*/
private long curPeriod() {
long period = _context.clock().now();
long ms = period % 1000;
if (ms > 500)
period = period - ms + 500;
else
period = period - ms;
return period;
}
private long getLifetime() { return System.currentTimeMillis() - _started; } private long getLifetime() { return System.currentTimeMillis() - _started; }
/** /**
@ -180,33 +163,24 @@ public class TunnelPool {
private TunnelInfo selectTunnel(boolean allowRecurseOnFail) { private TunnelInfo selectTunnel(boolean allowRecurseOnFail) {
boolean avoidZeroHop = !_settings.getAllowZeroHop(); boolean avoidZeroHop = !_settings.getAllowZeroHop();
long period = curPeriod();
synchronized (_tunnels) { synchronized (_tunnels) {
if (_lastSelectionPeriod == period) {
if ( (_lastSelected != null) &&
(_lastSelected.getExpiration() > period) &&
(_tunnels.contains(_lastSelected)) )
return _lastSelected;
}
_lastSelectionPeriod = period;
_lastSelected = null;
if (_tunnels.isEmpty()) { if (_tunnels.isEmpty()) {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
_log.warn(toString() + ": No tunnels to select from"); _log.warn(toString() + ": No tunnels to select from");
} else { } else {
Collections.shuffle(_tunnels, _context.random());
// if there are nonzero hop tunnels and the zero hop tunnels are fallbacks, // if there are nonzero hop tunnels and the zero hop tunnels are fallbacks,
// avoid the zero hop tunnels // avoid the zero hop tunnels
TunnelInfo backloggedTunnel = null; TunnelInfo backloggedTunnel = null;
if (avoidZeroHop) { if (avoidZeroHop) {
for (int i = 0; i < _tunnels.size(); i++) { for (int i = 0; i < _tunnels.size(); i++) {
TunnelInfo info = _tunnels.get(i); _lastSelectedIdx++;
if (_lastSelectedIdx >= _tunnels.size())
_lastSelectedIdx = 0;
TunnelInfo info = _tunnels.get(_lastSelectedIdx);
if ( (info.getLength() > 1) && (info.getExpiration() > _context.clock().now()) ) { if ( (info.getLength() > 1) && (info.getExpiration() > _context.clock().now()) ) {
// avoid outbound tunnels where the 1st hop is backlogged // avoid outbound tunnels where the 1st hop is backlogged
if (_settings.isInbound() || !_context.commSystem().isBacklogged(info.getPeer(1))) { if (_settings.isInbound() || !_context.commSystem().isBacklogged(info.getPeer(1))) {
_lastSelected = info;
return info; return info;
} else { } else {
backloggedTunnel = info; backloggedTunnel = info;
@ -229,7 +203,6 @@ public class TunnelPool {
if (_settings.isInbound() || info.getLength() <= 1 || if (_settings.isInbound() || info.getLength() <= 1 ||
!_context.commSystem().isBacklogged(info.getPeer(1))) { !_context.commSystem().isBacklogged(info.getPeer(1))) {
//_log.debug("Selecting tunnel: " + info + " - " + _tunnels); //_log.debug("Selecting tunnel: " + info + " - " + _tunnels);
_lastSelected = info;
return info; return info;
} else { } else {
backloggedTunnel = info; backloggedTunnel = info;
@ -505,10 +478,6 @@ public class TunnelPool {
if (_settings.isInbound() && !_settings.isExploratory()) if (_settings.isInbound() && !_settings.isExploratory())
ls = locked_buildNewLeaseSet(); ls = locked_buildNewLeaseSet();
remaining = _tunnels.size(); remaining = _tunnels.size();
if (_lastSelected == info) {
_lastSelected = null;
_lastSelectionPeriod = 0;
}
} }
_manager.getExecutor().repoll(); _manager.getExecutor().repoll();
@ -573,10 +542,6 @@ public class TunnelPool {
return; return;
if (_settings.isInbound() && !_settings.isExploratory()) if (_settings.isInbound() && !_settings.isExploratory())
ls = locked_buildNewLeaseSet(); ls = locked_buildNewLeaseSet();
if (_lastSelected == cfg) {
_lastSelected = null;
_lastSelectionPeriod = 0;
}
} }
_manager.tunnelFailed(); _manager.tunnelFailed();