More tinker
This commit is contained in:
@@ -134,7 +134,7 @@ public class RenderService<T extends AbstractSectionRenderer<J, ?>, J extends Vi
|
|||||||
this.sectionUpdateQueue.consume(128);
|
this.sectionUpdateQueue.consume(128);
|
||||||
|
|
||||||
//Cap the number of consumed sections per frame to 40 + 2% of the queue size, cap of 200
|
//Cap the number of consumed sections per frame to 40 + 2% of the queue size, cap of 200
|
||||||
int geoUpdateCap = Math.max(100, Math.min((int)(0.02*this.geometryUpdateQueue.count()), 200));
|
int geoUpdateCap = Math.max(100, Math.min((int)(0.15*this.geometryUpdateQueue.count()), 260));
|
||||||
this.geometryUpdateQueue.consume(geoUpdateCap);
|
this.geometryUpdateQueue.consume(geoUpdateCap);
|
||||||
if (this.nodeManager.writeChanges(this.traversal.getNodeBuffer())) {//TODO: maybe move the node buffer out of the traversal class
|
if (this.nodeManager.writeChanges(this.traversal.getNodeBuffer())) {//TODO: maybe move the node buffer out of the traversal class
|
||||||
UploadStream.INSTANCE.commit();
|
UploadStream.INSTANCE.commit();
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ import java.util.function.Supplier;
|
|||||||
//TODO: could also probably replace all of this with just VirtualThreads and a Executors.newThreadPerTaskExecutor with a fixed thread pool
|
//TODO: could also probably replace all of this with just VirtualThreads and a Executors.newThreadPerTaskExecutor with a fixed thread pool
|
||||||
// it is probably better anyway
|
// it is probably better anyway
|
||||||
public class ServiceThreadPool {
|
public class ServiceThreadPool {
|
||||||
/*
|
|
||||||
private static final ThreadMXBean THREAD_BEAN = ManagementFactory.getThreadMXBean();
|
private static final ThreadMXBean THREAD_BEAN = ManagementFactory.getThreadMXBean();
|
||||||
static {
|
static {
|
||||||
THREAD_BEAN.setThreadCpuTimeEnabled(true);
|
THREAD_BEAN.setThreadCpuTimeEnabled(true);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
private volatile boolean running = true;
|
private volatile boolean running = true;
|
||||||
private Thread[] workers = new Thread[0];
|
private Thread[] workers = new Thread[0];
|
||||||
@@ -135,6 +135,9 @@ public class ServiceThreadPool {
|
|||||||
private void worker(int threadId) {
|
private void worker(int threadId) {
|
||||||
long seed = 1234342;
|
long seed = 1234342;
|
||||||
int revolvingSelector = 0;
|
int revolvingSelector = 0;
|
||||||
|
|
||||||
|
double rollRuntimeRatio = 0;
|
||||||
|
double rollCpuTimeDelta = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
this.jobCounter.acquireUninterruptibly();
|
this.jobCounter.acquireUninterruptibly();
|
||||||
if (!this.running) {
|
if (!this.running) {
|
||||||
@@ -207,12 +210,40 @@ public class ServiceThreadPool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
VarHandle.fullFence();
|
||||||
|
long realTimeStart = System.nanoTime();
|
||||||
|
long cpuTimeStart = THREAD_BEAN.getCurrentThreadCpuTime();
|
||||||
|
VarHandle.fullFence();
|
||||||
|
*/
|
||||||
|
|
||||||
//Run the job
|
//Run the job
|
||||||
if (!service.doRun(threadId)) {
|
if (!service.doRun(threadId)) {
|
||||||
//Didnt consume the job, find a new job
|
//Didnt consume the job, find a new job
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
VarHandle.fullFence();
|
||||||
|
long cpuTimeEnd = THREAD_BEAN.getCurrentThreadCpuTime();
|
||||||
|
long realTimeEnd = System.nanoTime();
|
||||||
|
VarHandle.fullFence();
|
||||||
|
|
||||||
|
long realTimeDelta = realTimeEnd - realTimeStart;
|
||||||
|
long cpuTimeDelta = cpuTimeEnd - cpuTimeStart;
|
||||||
|
|
||||||
|
//Realtime should always be bigger or equal to cpu time
|
||||||
|
double runtimeRatio = ((double)cpuTimeDelta)/((double)realTimeDelta);
|
||||||
|
rollRuntimeRatio = (rollRuntimeRatio*0.95)+runtimeRatio*0.05;
|
||||||
|
rollCpuTimeDelta = (rollCpuTimeDelta*0.95)+cpuTimeDelta*0.05;
|
||||||
|
//Attempt to self balance cpu load
|
||||||
|
VarHandle.fullFence();
|
||||||
|
try {
|
||||||
|
if (rollRuntimeRatio > 0.8) {
|
||||||
|
Thread.sleep(Math.max((long) ((rollRuntimeRatio - 0.5) * (rollCpuTimeDelta / (1000 * 1000))), 1));
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}*/
|
||||||
|
|
||||||
//Consumed a job from the service, decrease weight by the amount
|
//Consumed a job from the service, decrease weight by the amount
|
||||||
if (this.totalJobWeight.addAndGet(-service.weightPerJob)<0) {
|
if (this.totalJobWeight.addAndGet(-service.weightPerJob)<0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user