mirror of
https://github.com/davidalves04/Trabalho-Pratico-SD.git
synced 2026-02-04 13:15:55 +00:00
fix: add micro-throttle for Linux performance parity
Linux runs too fast compared to Windows/Wine, causing vehicle queue backup (~44% completion vs 95% on Windows). Adding microsecond delays via LockSupport.parkNanos() achieves 92% completion. - 50μs delay in SocketConnection send/receive - 100μs delay in CoordinatorProcess vehicle generation
This commit is contained in:
@@ -3,6 +3,7 @@ package sd.coordinator;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
import sd.config.SimulationConfig;
|
||||
import sd.dashboard.DashboardStatistics;
|
||||
@@ -375,6 +376,7 @@ public class CoordinatorProcess {
|
||||
|
||||
String entryIntersection = vehicle.getRoute().get(0);
|
||||
sendVehicleToIntersection(vehicle, entryIntersection);
|
||||
LockSupport.parkNanos(100000); // 100us
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
import sd.serialization.MessageSerializer;
|
||||
import sd.serialization.SerializationException;
|
||||
@@ -167,7 +168,8 @@ public class SocketConnection implements Closeable {
|
||||
DataOutputStream dataOut = new DataOutputStream(outputStream);
|
||||
dataOut.writeInt(data.length);
|
||||
dataOut.write(data);
|
||||
dataOut.flush(); // Force transmission immediately
|
||||
dataOut.flush();
|
||||
LockSupport.parkNanos(50000); // 50us
|
||||
|
||||
} catch (SerializationException e) {
|
||||
throw new IOException("Failed to serialize message", e);
|
||||
@@ -202,6 +204,7 @@ public class SocketConnection implements Closeable {
|
||||
// Ler dados exatos da mensagem
|
||||
byte[] data = new byte[length];
|
||||
dataIn.readFully(data);
|
||||
LockSupport.parkNanos(50000); // 50us
|
||||
|
||||
// Deserialize do JSON - força o tipo concreto Message
|
||||
return serializer.deserialize(data, sd.model.Message.class);
|
||||
|
||||
Reference in New Issue
Block a user