/** * Wait for caching to finish, if there is time left in this request. */ @Override public void waitForCachingToFinish(List<Future<Integer>> pendingCachePuts) { Stopwatch stopwatch = Stopwatch.createStarted(); int columnCount = 0; for (Future<Integer> future : pendingCachePuts) { if (!future.isDone()) { long remainingMillis = ApiProxy.getCurrentEnvironment().getRemainingMillis(); if (remainingMillis > 100) { try { Integer cachedCount = future.get(remainingMillis - 50, TimeUnit.MILLISECONDS); columnCount += cachedCount; } catch (InterruptedException | TimeoutException e) { LOGGER.warning("Ran out of time while waiting for caching of results to complete."); return; } catch (ExecutionException e) { LOGGER.log(Level.WARNING, "Exception caching results of query", e); } } } } LOGGER.info("Waited " + stopwatch + " for " + columnCount + " columns to finish caching."); }
public static ListeningExecutorService currentRequestExecutorService() { ThreadFactory factory = checkNotNull(ThreadManager.currentRequestThreadFactory(), "ThreadManager.currentRequestThreadFactory()"); // GAE requests cannot exceed 10 threads per request int maxThreads = 10; long keepAlive = ApiProxy.getCurrentEnvironment().getRemainingMillis(); ExecutorService pool = newScalingThreadPool(0, maxThreads, keepAlive, factory); return WithSubmissionTrace.wrap(MoreExecutors.listeningDecorator(pool)); }
public static ListeningExecutorService currentRequestExecutorService() { ThreadFactory factory = checkNotNull(ThreadManager.currentRequestThreadFactory(), "ThreadManager.currentRequestThreadFactory()"); // GAE requests cannot exceed 10 threads per request int maxThreads = 10; long keepAlive = ApiProxy.getCurrentEnvironment().getRemainingMillis(); ExecutorService pool = newScalingThreadPool(0, maxThreads, keepAlive, factory); return WithSubmissionTrace.wrap(MoreExecutors.listeningDecorator(pool)); }
/** * @return {@code true} if there is time and space left to continue adding more snapshots, * or if we should stop here. */ public boolean timeAndSpaceRemaining() { // Do we have enough time left in this request to do any more work? long timeRemaining = ApiProxy.getCurrentEnvironment().getRemainingMillis(); if(timeRemaining < BUFFER_MS) { return false; } if(estimatedSizeInBytes > MAX_RESPONSE_SIZE) { return false; } return true; }