Skip to content

Commit

Permalink
Merge pull request #370 from nicolas-f/profiler_release
Browse files Browse the repository at this point in the history

    Propagation code now output a profiler csv file that helps to find bottleneck in the simulation (memory or writing speed on hdd)
    Now NoiseModelling is better able to maintain a constant number of active concurrent processes until the end of the simulation.
    Primary keys on lday, levening, lnight and lden are now applied only after all the insertion of rows (should be noticeable for large results)
    Precompute the position of image receivers before fetching the source. Instead of fetching the receiver image at each point source
  • Loading branch information
nicolas-f authored Jul 28, 2021
2 parents 4102e2f + 8b13c5f commit 7919073
Show file tree
Hide file tree
Showing 18 changed files with 614 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public LDENComputeRaysOut(PropagationProcessPathData pathData, LDENPropagationPr


@Override
public IComputeRaysOut subProcess(int receiverStart, int receiverEnd) {
public IComputeRaysOut subProcess() {
return new ThreadComputeRaysOut(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.noise_planet.noisemodelling.emission.DirectionAttributes;
import org.noise_planet.noisemodelling.emission.RailWayLW;
import org.noise_planet.noisemodelling.pathfinder.*;
import org.noise_planet.noisemodelling.pathfinder.utils.ProfilerThread;
import org.noise_planet.noisemodelling.propagation.*;
import org.noise_planet.noisemodelling.propagation.ComputeRaysOutAttenuation;
import org.slf4j.Logger;
Expand All @@ -41,7 +42,7 @@
/**
*
*/
public class LDENPointNoiseMapFactory implements PointNoiseMap.PropagationProcessDataFactory, PointNoiseMap.IComputeRaysOutFactory {
public class LDENPointNoiseMapFactory implements PointNoiseMap.PropagationProcessDataFactory, PointNoiseMap.IComputeRaysOutFactory, ProfilerThread.Metric {
LDENConfig ldenConfig;
TableWriter tableWriter;
Thread tableWriterThread;
Expand All @@ -59,6 +60,21 @@ public LDENPointNoiseMapFactory(Connection connection, LDENConfig ldenConfig) {
this.connection = connection;
}

@Override
public String[] getColumnNames() {
return new String[] {"jdbc_stack"};
}

@Override
public String[] getCurrentValues() {
return new String[] {Long.toString(ldenData.queueSize.get())};
}

@Override
public void tick(long currentMillis) {

}

public void insertTrainDirectivity() {
directionAttributes.clear();
directionAttributes.put(0, new LDENPropagationProcessData.OmnidirectionalDirection());
Expand Down Expand Up @@ -310,28 +326,36 @@ private String forgeCreateTable(String tableName) {
sb.append(" (IDRECEIVER bigint NOT NULL");
sb.append(", IDSOURCE bigint NOT NULL");
} else {
sb.append(" (IDRECEIVER SERIAL PRIMARY KEY");
sb.append(" (IDRECEIVER bigint NOT NULL");
}
for (int idfreq = 0; idfreq < ldenConfig.propagationProcessPathData.freq_lvl.size(); idfreq++) {
sb.append(", HZ");
sb.append(ldenConfig.propagationProcessPathData.freq_lvl.get(idfreq));
sb.append(" numeric(5, 2)");
}
sb.append(", LAEQ numeric(5, 2), LEQ numeric(5, 2)");
if(!ldenConfig.mergeSources) {
sb.append(", PRIMARY KEY(IDRECEIVER, IDSOURCE)");
}
sb.append(")");
return sb.toString();
}

private String forgePkTable(String tableName) {
StringBuilder sb = new StringBuilder("alter table ");
sb.append(tableName);
if (!ldenConfig.mergeSources) {
sb.append(" ADD PRIMARY KEY(IDRECEIVER, IDSOURCE)");
} else {
sb.append(" ADD PRIMARY KEY(IDRECEIVER)");
}
return sb.toString();
}

@Override
public void run() {
// Drop and create tables
try(Statement sql = connection.createStatement()) {
if(ldenConfig.exportRays) {
sql.execute(String.format("DROP TABLE IF EXISTS %s", ldenConfig.raysTable));
sql.execute("CREATE TABLE "+ldenConfig.raysTable+"(pk serial primary key, the_geom geometry, IDRECEIVER bigint NOT NULL, IDSOURCE bigint NOT NULL)");
sql.execute("CREATE TABLE "+ldenConfig.raysTable+"(pk bigint auto_increment, the_geom geometry, IDRECEIVER bigint NOT NULL, IDSOURCE bigint NOT NULL)");
}
if(ldenConfig.computeLDay) {
sql.execute(String.format("DROP TABLE IF EXISTS %s", ldenConfig.lDayTable));
Expand Down Expand Up @@ -374,6 +398,20 @@ public void run() {
break;
}
}
// Set primary keys
LOGGER.info("Write done, apply primary keys");
if(ldenConfig.computeLDay) {
sql.execute(forgePkTable(ldenConfig.lDayTable));
}
if(ldenConfig.computeLEvening) {
sql.execute(forgePkTable(ldenConfig.lEveningTable));
}
if(ldenConfig.computeLNight) {
sql.execute(forgePkTable(ldenConfig.lNightTable));
}
if(ldenConfig.computeLDEN) {
sql.execute(forgePkTable(ldenConfig.lDenTable));
}
} catch (SQLException e) {
LOGGER.error("SQL Writer exception", e);
LOGGER.error(e.getLocalizedMessage(), e.getNextException());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.index.strtree.STRtree;
import org.noise_planet.noisemodelling.pathfinder.ComputeRays;
import org.noise_planet.noisemodelling.pathfinder.utils.ProfilerThread;
import org.noise_planet.noisemodelling.propagation.ComputeRaysOutAttenuation;
import org.noise_planet.noisemodelling.pathfinder.FastObstructionTest;
import org.noise_planet.noisemodelling.pathfinder.IComputeRaysOut;
Expand Down Expand Up @@ -45,12 +46,32 @@ public class PointNoiseMap extends JdbcNoiseMap {
private IComputeRaysOutFactory computeRaysOutFactory;
private Logger logger = LoggerFactory.getLogger(PointNoiseMap.class);
private int threadCount = 0;
private ProfilerThread profilerThread;

public PointNoiseMap(String buildingsTableName, String sourcesTableName, String receiverTableName) {
super(buildingsTableName, sourcesTableName);
this.receiverTableName = receiverTableName;
}


/**
* Computation stacks and timing are collected by this class in order
* to profile the execution of the simulation
* @return Instance of ProfilerThread or null
*/
public ProfilerThread getProfilerThread() {
return profilerThread;
}

/**
* Computation stacks and timing are collected by this class in order
* to profile the execution of the simulation
* @param profilerThread Instance of ProfilerThread
*/
public void setProfilerThread(ProfilerThread profilerThread) {
this.profilerThread = profilerThread;
}

public void setComputeRaysOutFactory(IComputeRaysOutFactory computeRaysOutFactory) {
this.computeRaysOutFactory = computeRaysOutFactory;
}
Expand Down Expand Up @@ -249,6 +270,10 @@ public IComputeRaysOut evaluateCell(Connection connection, int cellI, int cellJ,

ComputeRays computeRays = new ComputeRays(threadData);

if(profilerThread != null) {
computeRays.setProfilerThread(profilerThread);
}

if(threadCount > 0) {
computeRays.setThreadCount(threadCount);
}
Expand Down
Loading

0 comments on commit 7919073

Please sign in to comment.