Search in sources :

Example 1 with TaskTracker

use of io.datarouter.instrumentation.task.TaskTracker in project datarouter by hotpads.

the class TableCountJob method run.

@Override
public void run(TaskTracker tracker) {
    tableSamplerService.scanCountableNodes().advanceUntil($ -> tracker.shouldStop()).each($ -> tracker.increment()).map(ClientTableEntityPrefixNameWrapper::new).each(item -> tracker.setLastItemProcessed(item.toString())).map(nodeNames -> tableSamplerService.getCurrentTableCountFromSamples(nodeNames.getClientName(), nodeNames.getTableName())).forEach(tableCount -> {
        tableCountDao.put(tableCount);
        latestTableCountDao.put(new LatestTableCount(tableCount));
    });
}
Also used : Inject(javax.inject.Inject) DatarouterTableCountDao(io.datarouter.nodewatch.storage.tablecount.DatarouterTableCountDao) DatarouterLatestTableCountDao(io.datarouter.nodewatch.storage.latesttablecount.DatarouterLatestTableCountDao) LatestTableCount(io.datarouter.nodewatch.storage.latesttablecount.LatestTableCount) TableSamplerService(io.datarouter.nodewatch.service.TableSamplerService) BaseJob(io.datarouter.job.BaseJob) TaskTracker(io.datarouter.instrumentation.task.TaskTracker) ClientTableEntityPrefixNameWrapper(io.datarouter.storage.node.tableconfig.ClientTableEntityPrefixNameWrapper) LatestTableCount(io.datarouter.nodewatch.storage.latesttablecount.LatestTableCount)

Example 2 with TaskTracker

use of io.datarouter.instrumentation.task.TaskTracker in project datarouter by hotpads.

the class JobRunner method runInTest.

private void runInTest(BaseJob job) {
    Class<? extends BaseJob> jobClass = job.getClass();
    TaskTracker tracker = new MemoryTaskTracker(jobClass);
    try {
        job.run(tracker);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MemoryTaskTracker(io.datarouter.instrumentation.task.MemoryTaskTracker) TaskTracker(io.datarouter.instrumentation.task.TaskTracker) MemoryTaskTracker(io.datarouter.instrumentation.task.MemoryTaskTracker)

Example 3 with TaskTracker

use of io.datarouter.instrumentation.task.TaskTracker in project datarouter by hotpads.

the class JobletDataVacuumJob method run.

@Override
public void run(TaskTracker tracker) throws RuntimeException {
    AtomicLong earliestCreated = new AtomicLong(Instant.now().toEpochMilli());
    jobletRequestDao.scan().advanceUntil($ -> tracker.shouldStop()).each($ -> tracker.increment()).forEach(jobletRequest -> {
        if (jobletRequest.getKey().getCreated() <= earliestCreated.longValue()) {
            earliestCreated.set(jobletRequest.getKey().getCreated());
        }
    });
    AtomicInteger jobletDeletionCount = new AtomicInteger(0);
    jobletDataDao.scan().advanceUntil($ -> tracker.shouldStop()).batch(1_000).each(batch -> tracker.increment(batch.size())).map(batch -> {
        return batch.stream().filter(data -> data.getCreated() == null || data.getCreated() < earliestCreated.longValue()).map(Databean::getKey).collect(Collectors.toList());
    }).each(jobletDataDao::deleteMulti).map(List::size).each(jobletDeletionCount::getAndAdd).forEach($ -> logger.warn("JobletDataVacuumJob deleted {} JobletDatas", NumberFormatter.addCommas(jobletDeletionCount)));
    logger.warn("Completed JobletDataVacuumJob deleted {} total JobletDatas", NumberFormatter.addCommas(jobletDeletionCount));
}
Also used : Logger(org.slf4j.Logger) BaseJob(io.datarouter.job.BaseJob) DatarouterJobletDataDao(io.datarouter.joblet.storage.jobletdata.DatarouterJobletDataDao) LoggerFactory(org.slf4j.LoggerFactory) TaskTracker(io.datarouter.instrumentation.task.TaskTracker) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) NumberFormatter(io.datarouter.util.number.NumberFormatter) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Databean(io.datarouter.model.databean.Databean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DatarouterJobletRequestDao(io.datarouter.joblet.storage.jobletrequest.DatarouterJobletRequestDao) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) List(java.util.List)

Example 4 with TaskTracker

use of io.datarouter.instrumentation.task.TaskTracker 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)

Example 5 with TaskTracker

use of io.datarouter.instrumentation.task.TaskTracker in project datarouter by hotpads.

the class ExampleTaskTrackerHandler method countFiles.

@Handler
public Mav countFiles(String parentPath, OptionalLong logEveryN) throws IOException {
    // create a TaskTracker
    TaskTracker tracker = trackerFactory.create(// determines the tracker name
    ExampleTaskTrackerHandler.class.getSimpleName(), // triggered by web request
    LongRunningTaskType.REQUEST, // deadline
    Instant.now().plus(Duration.ofMinutes(1)), // gracefully stop when the deadline is reached
    true, // record which user triggered the request, viewable in the UI
    getSessionInfo().getNonEmptyUsernameOrElse("anonymous"));
    // update and check the TaskTracker during a potentially long task
    Scanner.of(Files.walk(Paths.get(parentPath))).advanceUntil($ -> tracker.shouldStop()).map(Object::toString).each($ -> tracker.increment()).each(tracker::setLastItemProcessed).sample(logEveryN.orElse(1L), true).forEach(item -> logger.warn("{}={}", tracker.getCount(), item));
    // return a message to the user, obtaining the count from the tracker
    return new MessageMav("counted " + tracker.getCount());
}
Also used : TaskTracker(io.datarouter.instrumentation.task.TaskTracker) LongRunningTaskType(io.datarouter.tasktracker.scheduler.LongRunningTaskType) Scanner(io.datarouter.scanner.Scanner) LongRunningTaskTrackerFactory(io.datarouter.tasktracker.service.LongRunningTaskTrackerFactory) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Mav(io.datarouter.web.handler.mav.Mav) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) TaskTracker(io.datarouter.instrumentation.task.TaskTracker) Instant(java.time.Instant) OptionalLong(io.datarouter.web.handler.types.optional.OptionalLong) Inject(javax.inject.Inject) MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) Paths(java.nio.file.Paths) Duration(java.time.Duration) BaseHandler(io.datarouter.web.handler.BaseHandler) MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) BaseHandler(io.datarouter.web.handler.BaseHandler)

Aggregations

TaskTracker (io.datarouter.instrumentation.task.TaskTracker)6 Inject (javax.inject.Inject)4 BaseJob (io.datarouter.job.BaseJob)3 Scanner (io.datarouter.scanner.Scanner)2 Instant (java.time.Instant)2 List (java.util.List)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 DatarouterOpPerformanceRecordDao (io.datarouter.batchsizeoptimizer.storage.performancerecord.DatarouterOpPerformanceRecordDao)1 OpPerformanceRecord (io.datarouter.batchsizeoptimizer.storage.performancerecord.OpPerformanceRecord)1 OpPerformanceRecordKey (io.datarouter.batchsizeoptimizer.storage.performancerecord.OpPerformanceRecordKey)1 MemoryTaskTracker (io.datarouter.instrumentation.task.MemoryTaskTracker)1 DatarouterJobletDataDao (io.datarouter.joblet.storage.jobletdata.DatarouterJobletDataDao)1 DatarouterJobletRequestDao (io.datarouter.joblet.storage.jobletrequest.DatarouterJobletRequestDao)1 Databean (io.datarouter.model.databean.Databean)1 TableSamplerService (io.datarouter.nodewatch.service.TableSamplerService)1 DatarouterLatestTableCountDao (io.datarouter.nodewatch.storage.latesttablecount.DatarouterLatestTableCountDao)1 LatestTableCount (io.datarouter.nodewatch.storage.latesttablecount.LatestTableCount)1 DatarouterTableCountDao (io.datarouter.nodewatch.storage.tablecount.DatarouterTableCountDao)1 ClientTableEntityPrefixNameWrapper (io.datarouter.storage.node.tableconfig.ClientTableEntityPrefixNameWrapper)1