prevent parallel plot requests

Plotting can take a long time and use a lot of resources. 
Multiple plot requests can cause the machine to run OOM.

We are now allowing plots for 500k files again. This is mainly to
prevent unwanted plots of everything.
This commit is contained in:
ahr
2017-12-15 17:20:12 +01:00
parent 8d48726472
commit d63fabc85d
3 changed files with 40 additions and 11 deletions

View File

@@ -10,6 +10,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.SortedSet;
import java.util.concurrent.locks.ReentrantLock;
import org.lucares.pdb.datastore.Proposal;
import org.lucares.pdb.plot.api.PlotSettings;
@@ -50,6 +51,8 @@ public class PdbController implements HardcodedValues {
private final Plotter plotter;
private final PerformanceDb db;
private final ReentrantLock plotterLock = new ReentrantLock();
public PdbController(final PerformanceDb db, final Plotter plotter) {
this.db = db;
@@ -71,20 +74,32 @@ public class PdbController implements HardcodedValues {
produces = MediaType.APPLICATION_JSON_UTF8_VALUE //
)
@ResponseBody
PlotResponse createPlot(@RequestBody final PlotRequest request) throws InternalPlottingException {
PlotResponse createPlot(@RequestBody final PlotRequest request)
throws InternalPlottingException, InterruptedException {
final PlotSettings plotSettings = PlotSettingsTransformer.toSettings(request);
final PlotSettings plotSettings = PlotSettingsTransformer
.toSettings(request);
try {
final PlotResult result = plotter.plot(plotSettings);
// TODO the UI should cancel requests that are in flight before sending a plot request
if (plotterLock.tryLock()) {
try {
final PlotResult result = plotter.plot(plotSettings);
final String imageUrl = WEB_IMAGE_OUTPUT_PATH + "/" + result.getImageName();
LOGGER.trace("image url: {}", imageUrl);
System.gc();
final String imageUrl = WEB_IMAGE_OUTPUT_PATH + "/"
+ result.getImageName();
LOGGER.trace("image url: {}", imageUrl);
System.gc();
return new PlotResponse(DataSeries.toMap(result.getDataSeries()), imageUrl);
} catch (final NoDataPointsException e) {
throw new NotFoundException(e);
return new PlotResponse(
DataSeries.toMap(result.getDataSeries()), imageUrl);
} catch (final NoDataPointsException e) {
throw new NotFoundException(e);
} finally {
plotterLock.unlock();
}
} else {
throw new ServiceUnavailableException("Too many parallel requests!");
}
}