Work on managing update tile queue better
This commit is contained in:
parent
0385de578d
commit
e67bfad65a
2 changed files with 48 additions and 2 deletions
|
|
@ -16,12 +16,15 @@ public class AsynchronousQueue<T> {
|
||||||
private int dequeueTime;
|
private int dequeueTime;
|
||||||
private int accelDequeueTime;
|
private int accelDequeueTime;
|
||||||
private int accelDequeueThresh;
|
private int accelDequeueThresh;
|
||||||
|
private int pendingcnt;
|
||||||
|
private int pendinglimit;
|
||||||
|
|
||||||
public AsynchronousQueue(Handler<T> handler, int dequeueTime, int accelDequeueThresh, int accelDequeueTime) {
|
public AsynchronousQueue(Handler<T> handler, int dequeueTime, int accelDequeueThresh, int accelDequeueTime, int pendinglimit) {
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
this.dequeueTime = dequeueTime;
|
this.dequeueTime = dequeueTime;
|
||||||
this.accelDequeueTime = accelDequeueTime;
|
this.accelDequeueTime = accelDequeueTime;
|
||||||
this.accelDequeueThresh = accelDequeueThresh;
|
this.accelDequeueThresh = accelDequeueThresh;
|
||||||
|
this.pendinglimit = pendinglimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean push(T t) {
|
public boolean push(T t) {
|
||||||
|
|
@ -42,6 +45,16 @@ public class AsynchronousQueue<T> {
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean remove(T t) {
|
||||||
|
synchronized (lock) {
|
||||||
|
if (set.remove(t)) {
|
||||||
|
queue.remove(t);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
return set.size();
|
return set.size();
|
||||||
|
|
@ -95,8 +108,23 @@ public class AsynchronousQueue<T> {
|
||||||
private void running() {
|
private void running() {
|
||||||
try {
|
try {
|
||||||
while (Thread.currentThread() == thread) {
|
while (Thread.currentThread() == thread) {
|
||||||
|
synchronized(lock) {
|
||||||
|
while(pendingcnt >= pendinglimit) {
|
||||||
|
try {
|
||||||
|
lock.wait(accelDequeueTime);
|
||||||
|
} catch (InterruptedException ix) {
|
||||||
|
if(Thread.currentThread() != thread)
|
||||||
|
return;
|
||||||
|
throw ix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
T t = pop();
|
T t = pop();
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
|
synchronized(lock) {
|
||||||
|
pendingcnt++;
|
||||||
|
}
|
||||||
|
Log.info("handle(" + t + ")");
|
||||||
handler.handle(t);
|
handler.handle(t);
|
||||||
}
|
}
|
||||||
if(set.size() >= accelDequeueThresh)
|
if(set.size() >= accelDequeueThresh)
|
||||||
|
|
@ -118,4 +146,12 @@ public class AsynchronousQueue<T> {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void done(T t) {
|
||||||
|
Log.info("done(" + t + ")");
|
||||||
|
synchronized (lock) {
|
||||||
|
if(pendingcnt > 0) pendingcnt--;
|
||||||
|
lock.notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,7 @@ public class MapManager {
|
||||||
FullWorldRenderState(MapTile t) {
|
FullWorldRenderState(MapTile t) {
|
||||||
world = getWorld(t.getWorld().getName());
|
world = getWorld(t.getWorld().getName());
|
||||||
tile0 = t;
|
tile0 = t;
|
||||||
|
Log.info("job(" + t + ")");
|
||||||
cxmin = czmin = Integer.MIN_VALUE;
|
cxmin = czmin = Integer.MIN_VALUE;
|
||||||
cxmax = czmax = Integer.MAX_VALUE;
|
cxmax = czmax = Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
@ -315,6 +316,9 @@ public class MapManager {
|
||||||
active_renders.remove(world.world.getName());
|
active_renders.remove(world.world.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
tileQueue.done(tile0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void run() {
|
public void run() {
|
||||||
long tstart = System.currentTimeMillis();
|
long tstart = System.currentTimeMillis();
|
||||||
|
|
@ -506,6 +510,8 @@ public class MapManager {
|
||||||
tile.render(cache, null);
|
tile.render(cache, null);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
/* Remove tile from tile queue, since we're processing it already */
|
||||||
|
tileQueue.remove(tile);
|
||||||
/* Switch to not checking if rendered tile is blank - breaks us on skylands, where tiles can be nominally blank - just work off chunk cache empty */
|
/* Switch to not checking if rendered tile is blank - breaks us on skylands, where tiles can be nominally blank - just work off chunk cache empty */
|
||||||
if (cache.isEmpty() == false) {
|
if (cache.isEmpty() == false) {
|
||||||
tile.render(cache, mapname);
|
tile.render(cache, mapname);
|
||||||
|
|
@ -626,7 +632,7 @@ public class MapManager {
|
||||||
},
|
},
|
||||||
(int) (configuration.getDouble("renderinterval", 0.5) * 1000),
|
(int) (configuration.getDouble("renderinterval", 0.5) * 1000),
|
||||||
configuration.getInteger("renderacceleratethreshold", 30),
|
configuration.getInteger("renderacceleratethreshold", 30),
|
||||||
(int)(configuration.getDouble("renderaccelerateinterval", 0.2) * 1000));
|
(int)(configuration.getDouble("renderaccelerateinterval", 0.2) * 1000), 1);
|
||||||
|
|
||||||
/* On dedicated thread, so default to no delays */
|
/* On dedicated thread, so default to no delays */
|
||||||
timeslice_int = (long)(configuration.getDouble("timesliceinterval", 0.0) * 1000);
|
timeslice_int = (long)(configuration.getDouble("timesliceinterval", 0.0) * 1000);
|
||||||
|
|
@ -1121,6 +1127,10 @@ public class MapManager {
|
||||||
", updated=" + tot.updatedcnt + ", transparent=" + tot.transparentcnt);
|
", updated=" + tot.updatedcnt + ", transparent=" + tot.transparentcnt);
|
||||||
sender.sendMessage(" Cache hit rate: " + sscache.getHitRate() + "%");
|
sender.sendMessage(" Cache hit rate: " + sscache.getHitRate() + "%");
|
||||||
sender.sendMessage(" Triggered update queue size: " + tileQueue.size());
|
sender.sendMessage(" Triggered update queue size: " + tileQueue.size());
|
||||||
|
String act = "";
|
||||||
|
for(String wn : active_renders.keySet())
|
||||||
|
act += wn + " ";
|
||||||
|
sender.sendMessage(" Active render jobs: " + act);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Reset statistics
|
* Reset statistics
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue