Skip to content

Commit

Permalink
Merge pull request #372 from nicolas-f/profiler_release
Browse files Browse the repository at this point in the history
Add rays metrics
wps default to all available cpus
  • Loading branch information
nicolas-f authored Aug 3, 2021
2 parents 7919073 + 1fa690c commit 9a1d9bc
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public Map<CellIndex, Integer> searchPopulatedCells(Connection connection) throw
throw new SQLException("The table "+receiverTableName+" does not contain a Geometry field, then the extent " +
"cannot be computed");
}
logger.info("Collect all receivers in order to localize populated cells");
geometryField = geometryFields.get(0);
ResultSet rs = connection.createStatement().executeQuery("SELECT " + geometryField + " FROM " + receiverTableName);
// Construct RTree with cells envelopes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ public List<PropagationPath> computeReflexion(Coordinate receiverCoord, Coordina
List<FastObstructionTest.Wall> nearBuildingsWalls,
List<MirrorReceiverResult> receiverReflections) {
// Compute receiver mirror
LineSegment srcReceiver = new LineSegment(srcCoord, receiverCoord);
LineIntersector linters = new RobustLineIntersector();

List<PropagationPath> reflexionPropagationPaths = new ArrayList<>();
Expand Down Expand Up @@ -908,14 +907,12 @@ public List<PropagationPath> directPath(Coordinate srcCoord,

boolean freefield = true;
boolean topographyHideReceiver = false;
boolean buildingOnPath = false;

List<TriIdWithIntersection> inters = new ArrayList<>();
data.freeFieldFinder.computePropagationPath(srcCoord, receiverCoord, false, inters, true);
for (TriIdWithIntersection intersection : inters) {
if (intersection.getBuildingId() > 0) {
topographyHideReceiver = true;
buildingOnPath = true;
}
if (intersection.isIntersectionOnBuilding() || intersection.isIntersectionOnTopography()) {
freefield = false;
Expand Down Expand Up @@ -990,14 +987,13 @@ private double[] receiverSourcePropa(SourcePointInfo src,
Coordinate srcCoord = src.position;
int srcId = src.sourcePrimaryKey;
double sourceLi = src.li;
List<PropagationPath> propagationPaths;
// Build mirrored receiver list from wall list

double PropaDistance = srcCoord.distance(receiverCoord);
if (PropaDistance < data.maxSrcDist) {

// Process direct path (including horizontal and vertical diffractions)
propagationPaths = directPath(srcCoord, receiverCoord, data.isComputeVerticalDiffraction(), true);
// Process direct path (including horizontal and vertical diffraction)
List<PropagationPath> propagationPaths = directPath(srcCoord, receiverCoord, data.isComputeVerticalDiffraction(), true);

// Process specular reflection
if (data.reflexionOrder > 0) {
Expand All @@ -1013,6 +1009,12 @@ private double[] receiverSourcePropa(SourcePointInfo src,
// Compute the propagation source phi and theta
propagationPath.setSourceOrientation(src.getOrientation());
}

if(profilerThread != null &&
profilerThread.getMetric(ReceiverStatsMetric.class) != null) {
profilerThread.getMetric(ReceiverStatsMetric.class).onReceiverRays(rcvId, propagationPaths.size());
}

return dataOut.addPropagationPaths(srcId, sourceLi, rcvId, propagationPaths);
}
}
Expand Down Expand Up @@ -1079,8 +1081,7 @@ public void computeRaysAtPosition(Coordinate receiverCoord, int idReceiver, List
if (data.reflexionOrder > 0) {
wallsReceiver.addAll(data.freeFieldFinder.getLimitsInRange(
data.maxRefDist, receiverCoord, false));
new MirrorReceiverIterator.It(receiverCoord, wallsReceiver,
Integer.MAX_VALUE, data.reflexionOrder, data.maxSrcDist).forEach(mirrorReceiverResults::add);
new MirrorReceiverIterator.It(receiverCoord, wallsReceiver, data.reflexionOrder).forEach(mirrorReceiverResults::add);
}
double searchSourceDistance = data.maxSrcDist;
Envelope receiverSourceRegion = new Envelope(receiverCoord.x
Expand Down Expand Up @@ -1199,6 +1200,11 @@ public void runDebug(IComputeRaysOut computeRaysOut, List<PropagationDebugInfo>
// maxSrcDist meters
ProgressVisitor propaProcessProgression = data.cellProg;

if(threadCount == 0) {
Runtime runtime = Runtime.getRuntime();
this.threadCount = Math.max(1, runtime.availableProcessors());
}

ThreadPool threadManager = new ThreadPool(
threadCount,
threadCount + 1, Long.MAX_VALUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ public ComputeRaysOut(boolean keepRays) {

public boolean keepRays = true;
public AtomicLong rayCount = new AtomicLong();
public AtomicLong nb_couple_receiver_src = new AtomicLong();
public AtomicLong nb_obstr_test = new AtomicLong();
public AtomicLong nb_image_receiver = new AtomicLong();
public AtomicLong nb_reflexion_path = new AtomicLong();
public AtomicLong nb_diffraction_path = new AtomicLong();
public AtomicInteger cellComputed = new AtomicInteger();

@Override
public void finalizeReceiver(long receiverId) {
Expand Down Expand Up @@ -101,42 +95,6 @@ public void clearPropagationPaths() {
this.propagationPaths.clear();
}

public void appendReflexionPath(long added) {
nb_reflexion_path.addAndGet(added);
}

public void appendDiffractionPath(long added) {
nb_diffraction_path.addAndGet(added);
}

public void appendImageReceiver(long added) {
nb_image_receiver.addAndGet(added);
}

public void appendSourceCount(long srcCount) {
nb_couple_receiver_src.addAndGet(srcCount);
}

public void appendFreeFieldTestCount(long freeFieldTestCount) {
nb_obstr_test.addAndGet(freeFieldTestCount);
}

public synchronized void log(String str) {

}

/**
* Increment cell computed counter by 1
*/
public synchronized void appendCellComputed() {
cellComputed.addAndGet(1);
}

public synchronized long getCellComputed() {
return cellComputed.get();
}


public static class ThreadRaysOut implements IComputeRaysOut {
protected ComputeRaysOut multiThreadParent;
public List<PropagationPath> propagationPaths = new ArrayList<PropagationPath>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,16 @@
public class MirrorReceiverIterator implements Iterator<MirrorReceiverResult> {
private final Coordinate receiverCoord;
private final List<FastObstructionTest.Wall> nearBuildingsWalls;
private final double distanceLimitation;
private final double propagationLimitation;
// Wall stack
private CrossTableIterator wallIdentifierIt;
private MirrorReceiverResult current = null;
private final int maxDepth;

private MirrorReceiverIterator(Coordinate receiverCoord, List<FastObstructionTest.Wall> nearBuildingsWalls
, double distanceLimitation, int maxDepth, double propagationLimitation) {
, int maxDepth) {
this.receiverCoord = receiverCoord;
this.nearBuildingsWalls = nearBuildingsWalls;
this.distanceLimitation = distanceLimitation;
this.wallIdentifierIt = new CrossTableIterator(maxDepth, nearBuildingsWalls.size());
this.propagationLimitation = propagationLimitation;
this.maxDepth = maxDepth;
fetchNext();
}
Expand Down Expand Up @@ -171,23 +167,19 @@ public static boolean wallPointTest(LineSegment wall1, Coordinate pt) {
public static final class It implements Iterable<MirrorReceiverResult> {
private final Coordinate receiverCoord;
private final List<FastObstructionTest.Wall> nearBuildingsWalls;
private final double distanceLimitation;
private final int maxDepth;
private final double propagationLimitation;

public It(Coordinate receiverCoord, List<FastObstructionTest.Wall> nearBuildingsWalls,
double distanceLimitation, int maxDepth, double propagationLimitation) {
public It(Coordinate receiverCoord, List<FastObstructionTest.Wall> nearBuildingsWalls
, int maxDepth) {
this.receiverCoord = receiverCoord;
this.nearBuildingsWalls = nearBuildingsWalls;
this.distanceLimitation = distanceLimitation;
this.maxDepth = maxDepth;
this.propagationLimitation = propagationLimitation;
}

@Override
public java.util.Iterator<MirrorReceiverResult> iterator() {
return new MirrorReceiverIterator(receiverCoord, nearBuildingsWalls, distanceLimitation,
maxDepth,propagationLimitation);
return new MirrorReceiverIterator(receiverCoord, nearBuildingsWalls,
maxDepth);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,49 +41,71 @@
* Generate stats about receiver computation time
*/
public class ReceiverStatsMetric implements ProfilerThread.Metric {
public static final String RECEIVER_COMPUTATION_TIME = "RECEIVER_COMPUTATION_TIME";
private ConcurrentLinkedDeque<ReceiverProfile> receiverProfiles = new ConcurrentLinkedDeque<>();
private DescriptiveStatistics stats = new DescriptiveStatistics();
private ConcurrentLinkedDeque<ReceiverComputationTime> receiverComputationTimes = new ConcurrentLinkedDeque<>();
private ConcurrentLinkedDeque<ReceiverRays> receiverRaysDeque = new ConcurrentLinkedDeque<>();
private DescriptiveStatistics computationTime = new DescriptiveStatistics();
private DescriptiveStatistics computationRays = new DescriptiveStatistics();

public ReceiverStatsMetric() {
}

@Override
public void tick(long currentMillis) {
while (!receiverProfiles.isEmpty()) {
ReceiverProfile receiverProfile = receiverProfiles.pop();
stats.addValue(receiverProfile.computationTime);
while (!receiverComputationTimes.isEmpty()) {
ReceiverComputationTime receiverProfile = receiverComputationTimes.pop();
computationTime.addValue(receiverProfile.computationTime);
}
while (!receiverRaysDeque.isEmpty()) {
ReceiverRays receiverProfile = receiverRaysDeque.pop();
computationRays.addValue(receiverProfile.numberOfRays);
}
}

@Override
public String[] getColumnNames() {
return new String[] {"receiver_min","receiver_median","receiver_mean","receiver_max"};
return new String[] {"receiver_min","receiver_median","receiver_mean","receiver_max", "receiver_median_rays", "receiver_max_rays"};
}

public void onEndComputation(int receiverId, int computationTime) {
receiverProfiles.add(new ReceiverProfile(receiverId, computationTime));
receiverComputationTimes.add(new ReceiverComputationTime(receiverId, computationTime));
}

public void onReceiverRays(int receiverId, int receiverRays) {
receiverRaysDeque.add(new ReceiverRays(receiverId, receiverRays));
}

@Override
public String[] getCurrentValues() {
String[] res = new String[] {
Integer.toString((int)stats.getMin()),
Integer.toString((int)stats.getPercentile(50)),
Integer.toString((int)stats.getMean()),
Integer.toString((int)stats.getMax())
Integer.toString((int) computationTime.getMin()),
Integer.toString((int) computationTime.getPercentile(50)),
Integer.toString((int) computationTime.getMean()),
Integer.toString((int) computationTime.getMax()),
Integer.toString((int) computationRays.getPercentile(50)),
Integer.toString((int) computationRays.getMax())
};
stats.clear();
computationTime.clear();
computationRays.clear();
return res;
}

public static class ReceiverProfile {
private static class ReceiverComputationTime {
public int receiverId;
public int computationTime;

public ReceiverProfile(int receiverId, int computationTime) {
public ReceiverComputationTime(int receiverId, int computationTime) {
this.receiverId = receiverId;
this.computationTime = computationTime;
}
}

private static class ReceiverRays {
public int receiverId;
public int numberOfRays;

public ReceiverRays(int receiverId, int numberOfRays) {
this.receiverId = receiverId;
this.numberOfRays = numberOfRays;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ public void TestcomputeVerticalEdgeDiffraction() throws LayerDelaunayError, Pars
assertEquals(0, new Coordinate(10, 4).distance(ray.get(i++)), 0.02);
assertEquals(0, new Coordinate(6, 5).distance(ray.get(i++)), 0.02);
assertEquals(0, p1.distance(ray.get(i++)), 0.02);

p1 = new Coordinate(5.04, 3.25, 1.6);
p2 = new Coordinate(14.88, 8.39, 1.6);
ray = computeRays.computeSideHull(true, p2, p1);
i = 0;
assertEquals(0, p2.distance(ray.get(i++)), 0.02);
assertEquals(0, new Coordinate(11, 4).distance(ray.get(i++)), 0.02);
assertEquals(0, p1.distance(ray.get(i++)), 0.02);

ray = computeRays.computeSideHull(false, p2, p1);
i = 0;
assertEquals(0, p2.distance(ray.get(i++)), 0.02);
assertEquals(0, new Coordinate(10, 6).distance(ray.get(i++)), 0.02);
assertEquals(0, p1.distance(ray.get(i++)), 0.02);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void testWallVisibility () {

public static List<MirrorReceiverResult> getReceiverImages(Coordinate receiver, Coordinate source, List<FastObstructionTest.Wall> walls, int order) {
MirrorReceiverIterator.It mirrorReceiverResults =
new MirrorReceiverIterator.It(receiver, walls, 9999, order, 9999);
new MirrorReceiverIterator.It(receiver, walls, order);

List<MirrorReceiverResult> res = new ArrayList<>();
for(MirrorReceiverResult r : mirrorReceiverResults) {
Expand Down Expand Up @@ -240,7 +240,7 @@ public void testWallReceiverImage() {
Coordinate source = new Coordinate(9, 4);

MirrorReceiverIterator.It mirrorReceiverResults =
new MirrorReceiverIterator.It(receiver, walls, 20, 2, 40);
new MirrorReceiverIterator.It(receiver, walls, 2);
Iterator<MirrorReceiverResult> it = mirrorReceiverResults.iterator();
wallTest(new Coordinate(0, 2), new int[]{0}, it.next());
wallTest(new Coordinate(6, 2), new int[]{0, 4}, it.next());
Expand Down Expand Up @@ -341,8 +341,7 @@ public void testPath() throws ParseException, LayerDelaunayError {
assertEquals(13, walls.size());
List<PropagationPath> paths;
List<MirrorReceiverResult> mirrorReceiverResults = new ArrayList<>();
new MirrorReceiverIterator.It(receiver, walls,
Integer.MAX_VALUE, data.reflexionOrder, data.maxSrcDist).forEach(mirrorReceiverResults::add);
new MirrorReceiverIterator.It(receiver, walls, data.reflexionOrder).forEach(mirrorReceiverResults::add);
paths = computeRays.computeReflexion(receiver, source, false, walls, mirrorReceiverResults);
assertEquals(1, paths.size());
List<PointPath> pts = paths.get(0).getPointList();
Expand All @@ -356,8 +355,7 @@ public void testPath() throws ParseException, LayerDelaunayError {

data.reflexionOrder = 2;
mirrorReceiverResults = new ArrayList<>();
new MirrorReceiverIterator.It(receiver, walls,
Integer.MAX_VALUE, data.reflexionOrder, data.maxSrcDist).forEach(mirrorReceiverResults::add);
new MirrorReceiverIterator.It(receiver, walls, data.reflexionOrder).forEach(mirrorReceiverResults::add);
paths = computeRays.computeReflexion(receiver, source, false, walls, mirrorReceiverResults);
assertEquals(2, paths.size());
pts = paths.get(1).getPointList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
import org.h2gis.functions.io.csv.CSVDriverFunction;
import org.h2gis.functions.io.geojson.GeoJsonRead;
import org.h2gis.utilities.SFSUtilities;
import org.noise_planet.noisemodelling.pathfinder.utils.JVMMemoryMetric;
import org.noise_planet.noisemodelling.pathfinder.utils.KMLDocument;
import org.noise_planet.noisemodelling.pathfinder.utils.*;
import org.noise_planet.noisemodelling.jdbc.LDENConfig;
import org.noise_planet.noisemodelling.jdbc.LDENPointNoiseMapFactory;
import org.noise_planet.noisemodelling.jdbc.PointNoiseMap;
import org.noise_planet.noisemodelling.pathfinder.FastObstructionTest;
import org.noise_planet.noisemodelling.pathfinder.IComputeRaysOut;
import org.noise_planet.noisemodelling.pathfinder.RootProgressVisitor;
import org.noise_planet.noisemodelling.pathfinder.utils.ProfilerThread;
import org.noise_planet.noisemodelling.pathfinder.utils.ProgressMetric;
import org.noise_planet.noisemodelling.propagation.ComputeRaysOutAttenuation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -142,6 +139,7 @@ public static void main(String[] args) throws SQLException, IOException {
profilerThread.addMetric(tableWriter);
profilerThread.addMetric(new ProgressMetric(progressLogger));
profilerThread.addMetric(new JVMMemoryMetric());
profilerThread.addMetric(new ReceiverStatsMetric());
profilerThread.setWriteInterval(2);
profilerThread.setFlushInterval(15);
pointNoiseMap.setProfilerThread(profilerThread);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.locationtech.jts.geom.GeometryFactory
import org.noise_planet.noisemodelling.emission.*
import org.noise_planet.noisemodelling.pathfinder.*
import org.noise_planet.noisemodelling.pathfinder.utils.JVMMemoryMetric
import org.noise_planet.noisemodelling.pathfinder.utils.ReceiverStatsMetric
import org.noise_planet.noisemodelling.pathfinder.utils.ProfilerThread
import org.noise_planet.noisemodelling.pathfinder.utils.ProgressMetric
import org.noise_planet.noisemodelling.propagation.*
Expand Down Expand Up @@ -152,7 +153,7 @@ inputs = [
description: 'Number of thread to use on the computer (INTEGER).' +
'</br> To set this value, look at the number of cores you have.' +
'</br> If it is set to 0, use the maximum number of cores available.' +
'</br> </br> <b> Default value : 1 </b>',
'</br> </br> <b> Default value : 0 </b>',
min : 0, max: 1, type: String.class
],
confDiffVertical : [
Expand Down Expand Up @@ -421,7 +422,7 @@ def exec(Connection connection, input) {
wall_alpha = Double.valueOf(input['paramWallAlpha'])
}

int n_thread = 1
int n_thread = 0
if (input['confThreadNumber']) {
n_thread = Integer.valueOf(input['confThreadNumber'])
}
Expand Down Expand Up @@ -556,6 +557,7 @@ def exec(Connection connection, input) {
profilerThread.addMetric(ldenProcessing);
profilerThread.addMetric(new ProgressMetric(progressLogger));
profilerThread.addMetric(new JVMMemoryMetric());
profilerThread.addMetric(new ReceiverStatsMetric());
profilerThread.setWriteInterval(300);
profilerThread.setFlushInterval(300);
pointNoiseMap.setProfilerThread(profilerThread);
Expand Down
Loading

0 comments on commit 9a1d9bc

Please sign in to comment.