Search in sources :

Example 1 with OpPerformanceRecordKey

use of io.datarouter.batchsizeoptimizer.storage.performancerecord.OpPerformanceRecordKey in project datarouter by hotpads.

the class OpPerformanceRecordAggregationJob method run.

@Override
public void run(TaskTracker tracker) {
    String currentOpName = null;
    List<OpPerformanceRecordKey> recordsToDelete = new ArrayList<>(BATCH_SIZE);
    Map<Integer, AggregatedRecord> aggregatedRecordsByBatchSize = new HashMap<>();
    for (OpPerformanceRecord record : opPerformanceRecordDao.scan().iterable()) {
        if (currentOpName != null && !currentOpName.equals(record.getKey().getOpName())) {
            saveAggregatedRecord(aggregatedRecordsByBatchSize);
            aggregatedRecordsByBatchSize.clear();
        }
        currentOpName = record.getKey().getOpName();
        aggregatedRecordsByBatchSize.computeIfAbsent(record.getBatchSize(), $ -> new AggregatedRecord(record.getKey().getOpName(), record.getBatchSize())).addRecord(record);
        recordsToDelete.add(record.getKey());
        if (recordsToDelete.size() > BATCH_SIZE) {
            opPerformanceRecordDao.deleteMulti(new ArrayList<>(recordsToDelete));
            recordsToDelete.clear();
        }
    }
    saveAggregatedRecord(aggregatedRecordsByBatchSize);
    opPerformanceRecordDao.deleteMulti(recordsToDelete);
}
Also used : Inject(javax.inject.Inject) Scanner(io.datarouter.scanner.Scanner) List(java.util.List) OpPerformanceRecordKey(io.datarouter.batchsizeoptimizer.storage.performancerecord.OpPerformanceRecordKey) BaseJob(io.datarouter.job.BaseJob) Map(java.util.Map) HashMap(java.util.HashMap) TaskTracker(io.datarouter.instrumentation.task.TaskTracker) DatarouterOpPerformanceRecordDao(io.datarouter.batchsizeoptimizer.storage.performancerecord.DatarouterOpPerformanceRecordDao) OpPerformanceRecord(io.datarouter.batchsizeoptimizer.storage.performancerecord.OpPerformanceRecord) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OpPerformanceRecord(io.datarouter.batchsizeoptimizer.storage.performancerecord.OpPerformanceRecord) OpPerformanceRecordKey(io.datarouter.batchsizeoptimizer.storage.performancerecord.OpPerformanceRecordKey)

Aggregations

DatarouterOpPerformanceRecordDao (io.datarouter.batchsizeoptimizer.storage.performancerecord.DatarouterOpPerformanceRecordDao)1 OpPerformanceRecord (io.datarouter.batchsizeoptimizer.storage.performancerecord.OpPerformanceRecord)1 OpPerformanceRecordKey (io.datarouter.batchsizeoptimizer.storage.performancerecord.OpPerformanceRecordKey)1 TaskTracker (io.datarouter.instrumentation.task.TaskTracker)1 BaseJob (io.datarouter.job.BaseJob)1 Scanner (io.datarouter.scanner.Scanner)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Inject (javax.inject.Inject)1