public SplitConcurrencyController(int initialConcurrency, Duration adjustmentInterval) { checkArgument(initialConcurrency > 0, "initial concurrency must be positive"); this.targetConcurrency = initialConcurrency; this.adjustmentIntervalNanos = adjustmentInterval.roundTo(NANOSECONDS); }
@Override public TableWriterInfo mergeWith(TableWriterInfo other) { return new TableWriterInfo( Math.max(pageSinkPeakMemoryUsage, other.pageSinkPeakMemoryUsage), succinctNanos(statisticsWallTime.roundTo(NANOSECONDS) + other.statisticsWallTime.roundTo(NANOSECONDS)), succinctNanos(statisticsCpuTime.roundTo(NANOSECONDS) + other.statisticsCpuTime.roundTo(NANOSECONDS)), succinctNanos(validationCpuTime.roundTo(NANOSECONDS) + other.validationCpuTime.roundTo(NANOSECONDS))); }
public static String formatTime(Duration duration) { int totalSeconds = Ints.saturatedCast(duration.roundTo(SECONDS)); int minutes = totalSeconds / 60; int seconds = totalSeconds % 60; return format("%s:%02d", minutes, seconds); }
@VisibleForTesting public Backoff(int minTries, Duration maxFailureInterval, Ticker ticker, List<Duration> backoffDelayIntervals) { checkArgument(minTries > 0, "minTries must be at least 1"); requireNonNull(maxFailureInterval, "maxFailureInterval is null"); requireNonNull(ticker, "ticker is null"); requireNonNull(backoffDelayIntervals, "backoffDelayIntervals is null"); checkArgument(!backoffDelayIntervals.isEmpty(), "backoffDelayIntervals must contain at least one entry"); this.minTries = minTries; this.maxFailureIntervalNanos = maxFailureInterval.roundTo(NANOSECONDS); this.ticker = ticker; this.backoffDelayIntervalsNanos = backoffDelayIntervals.stream() .mapToLong(duration -> duration.roundTo(NANOSECONDS)) .toArray(); }
public void start() { DateTime now = DateTime.now(); executionStartTime.compareAndSet(null, now); startNanos.compareAndSet(0, System.nanoTime()); startFullGcCount.compareAndSet(-1, gcMonitor.getMajorGcCount()); startFullGcTimeNanos.compareAndSet(-1, gcMonitor.getMajorGcTime().roundTo(NANOSECONDS)); // always update last execution start time lastExecutionStartTime.set(now); }
public Duration getFullGcTime() { long startFullGcTimeNanos = this.startFullGcTimeNanos.get(); if (startFullGcTimeNanos < 0) { return new Duration(0, MILLISECONDS); } long endFullGcTimeNanos = this.endFullGcTimeNanos.get(); if (endFullGcTimeNanos < 0) { endFullGcTimeNanos = gcMonitor.getMajorGcTime().roundTo(NANOSECONDS); } return new Duration(max(0, endFullGcTimeNanos - startFullGcTimeNanos), NANOSECONDS); }
private void updateStatsIfDone(TaskState newState) { if (newState.isDone()) { DateTime now = DateTime.now(); long majorGcCount = gcMonitor.getMajorGcCount(); long majorGcTime = gcMonitor.getMajorGcTime().roundTo(NANOSECONDS); // before setting the end times, make sure a start has been recorded executionStartTime.compareAndSet(null, now); startNanos.compareAndSet(0, System.nanoTime()); startFullGcCount.compareAndSet(-1, majorGcCount); startFullGcTimeNanos.compareAndSet(-1, majorGcTime); // Only update last start time, if the nothing was started lastExecutionStartTime.compareAndSet(null, now); // use compare and set from initial value to avoid overwriting if there // were a duplicate notification, which shouldn't happen executionEndTime.compareAndSet(null, now); endNanos.compareAndSet(0, System.nanoTime()); endFullGcCount.compareAndSet(-1, majorGcCount); endFullGcTimeNanos.compareAndSet(-1, majorGcTime); } }
@GET @Path("{taskId}/status") @Produces(MediaType.APPLICATION_JSON) public synchronized TaskStatus getTaskStatus( @PathParam("taskId") TaskId taskId, @HeaderParam(PRESTO_CURRENT_STATE) TaskState currentState, @HeaderParam(PRESTO_MAX_WAIT) Duration maxWait, @Context UriInfo uriInfo) throws InterruptedException { lastActivityNanos.set(System.nanoTime()); wait(maxWait.roundTo(MILLISECONDS)); return buildTaskStatus(); }
long quantaCpuNanos = elapsed.getCpu().roundTo(NANOSECONDS); cpuTimeNanos.addAndGet(quantaCpuNanos);
queuedTime.add(driverStats.getQueuedTime().roundTo(NANOSECONDS)); elapsedTime.add(driverStats.getElapsedTime().roundTo(NANOSECONDS)); totalScheduledTime.getAndAdd(driverStats.getTotalScheduledTime().roundTo(NANOSECONDS)); totalCpuTime.getAndAdd(driverStats.getTotalCpuTime().roundTo(NANOSECONDS)); totalBlockedTime.getAndAdd(driverStats.getTotalBlockedTime().roundTo(NANOSECONDS));
public static void refreshSizeEstimates(String keyspace, String table) throws Exception { long deadline = System.nanoTime() + REFRESH_SIZE_ESTIMATES_TIMEOUT.roundTo(NANOSECONDS); while (System.nanoTime() - deadline < 0) { flushTable(keyspace, table); refreshSizeEstimates(); List<SizeEstimate> sizeEstimates = getSession().getSizeEstimates(keyspace, table); if (!sizeEstimates.isEmpty()) { log.info("Size estimates for the table %s.%s have been refreshed successfully: %s", keyspace, table, sizeEstimates); return; } log.info("Size estimates haven't been refreshed as expected. Retrying ..."); SECONDS.sleep(1); } throw new TimeoutException(format("Attempting to refresh size estimates for table %s.%s has timed out after %s", keyspace, table, REFRESH_SIZE_ESTIMATES_TIMEOUT)); }
long maxRuntime = duration.roundTo(TimeUnit.NANOSECONDS);
@Test public void testMinTries() { TestingTicker ticker = new TestingTicker(); ticker.increment(1, NANOSECONDS); Backoff backoff = new Backoff(3, new Duration(1, NANOSECONDS), ticker, ImmutableList.of(new Duration(10, MILLISECONDS))); ticker.increment(10, MICROSECONDS); // verify initial state assertEquals(backoff.getFailureCount(), 0); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 0); // first failure, should never fail assertFalse(backoff.failure()); assertEquals(backoff.getFailureCount(), 1); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 0); ticker.increment(14, SECONDS); // second failure under min failures, should not fail assertFalse(backoff.failure()); assertEquals(backoff.getFailureCount(), 2); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 14); ticker.increment(1, SECONDS); // last try failed assertTrue(backoff.failure()); assertEquals(backoff.getFailureCount(), 3); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 15); }
@Test public void testFailureInterval() { TestingTicker ticker = new TestingTicker(); ticker.increment(1, NANOSECONDS); Backoff backoff = new Backoff(1, new Duration(15, SECONDS), ticker, ImmutableList.of(new Duration(10, MILLISECONDS))); ticker.increment(10, MICROSECONDS); // verify initial state assertEquals(backoff.getFailureCount(), 0); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 0); // first failure, should never fail assertFalse(backoff.failure()); assertEquals(backoff.getFailureCount(), 1); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 0); ticker.increment(14, SECONDS); // second failure within the limit, should not fail assertFalse(backoff.failure()); assertEquals(backoff.getFailureCount(), 2); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 14); ticker.increment(1, SECONDS); // final failure after the limit causes failure assertTrue(backoff.failure()); assertEquals(backoff.getFailureCount(), 3); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 15); }
@Test public void testStartRequest() { TestingTicker ticker = new TestingTicker(); ticker.increment(1, NANOSECONDS); Backoff backoff = new Backoff(1, new Duration(15, SECONDS), ticker, ImmutableList.of(new Duration(10, MILLISECONDS))); ticker.increment(10, MICROSECONDS); assertFalse(backoff.failure()); assertEquals(backoff.getFailureCount(), 1); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 0); assertEquals(backoff.getFailureRequestTimeTotal().roundTo(SECONDS), 0); ticker.increment(7, SECONDS); backoff.startRequest(); ticker.increment(7, SECONDS); assertFalse(backoff.failure()); assertEquals(backoff.getFailureCount(), 2); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 14); // failed request took 7 seconds. assertEquals(backoff.getFailureRequestTimeTotal().roundTo(SECONDS), 7); ticker.increment(1, SECONDS); backoff.startRequest(); ticker.increment(1, SECONDS); assertTrue(backoff.failure()); assertEquals(backoff.getFailureCount(), 3); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 16); // failed requests took 7+1 seconds. assertEquals(backoff.getFailureRequestTimeTotal().roundTo(SECONDS), 8); }
public static void waitForGlobalResourceGroup(DistributedQueryRunner queryRunner) throws InterruptedException { long startTime = System.nanoTime(); while (true) { SECONDS.sleep(1); ResourceGroupInfo global = getResourceGroupManager(queryRunner).getResourceGroupInfo(new ResourceGroupId("global")); if (global.getSoftMemoryLimit().toBytes() > 0) { break; } assertLessThan(nanosSince(startTime).roundTo(SECONDS), 60L); } }
.put("input_megabytes_per_second", (long) (inputMegaBytes / executionTime.getWall().getValue(SECONDS))) .put("wall_nanos", executionTime.getWall().roundTo(NANOSECONDS)) .put("cpu_nanos", executionTime.getCpu().roundTo(NANOSECONDS)) .put("user_nanos", executionTime.getUser().roundTo(NANOSECONDS)) .put("input_rows", inputRows) .put("input_bytes", inputBytes)
assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 0); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 0); long backoffDelay = backoff.getBackoffDelayNanos(); assertEquals(NANOSECONDS.toSeconds(backoffDelay), 0); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 0); backoffDelay = backoff.getBackoffDelayNanos(); assertEquals(NANOSECONDS.toSeconds(backoffDelay), 1); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 1); backoffDelay = backoff.getBackoffDelayNanos(); assertEquals(NANOSECONDS.toSeconds(backoffDelay), 2); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 3); backoffDelay = backoff.getBackoffDelayNanos(); assertEquals(NANOSECONDS.toSeconds(backoffDelay), 4); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 7); backoffDelay = backoff.getBackoffDelayNanos(); assertEquals(NANOSECONDS.toSeconds(backoffDelay), 8); assertEquals(backoff.getFailureDuration().roundTo(SECONDS), 15); backoffDelay = backoff.getBackoffDelayNanos(); assertEquals(NANOSECONDS.toSeconds(backoffDelay), 8);