/** * A processing thread would check in with out-of-core engine every once in a * while to make sure that it can still remain active. It is the * responsibility of the out-of-core oracle to update the number of active * threads in a way that the computation never fails, and yet achieve the * optimal performance it can achieve. */ public void activeThreadCheckIn() { activeThreadsPermit.release(); try { activeThreadsPermit.acquire(); } catch (InterruptedException e) { LOG.error("activeThreadCheckIn: exception while acquiring a permit to " + "remain an active thread"); throw new IllegalStateException(e); } }
/** * Adjusts the maximum number of available permits. * * @param newMax max number of permits */ public synchronized void setMaxPermits(int newMax) { checkState(newMax >= 0, "setMaxPermits: number of permits cannot be " + "less than 0"); int delta = newMax - this.maxPermits; if (delta > 0) { // Releasing semaphore to make room for 'delta' more permits release(delta); } else if (delta < 0) { // Reducing number of permits in the semaphore reducePermits(-delta); } this.maxPermits = newMax; } }
/** * Update the fraction of processing threads that should remain active. It is * the responsibility of out-of-core oracle to update the number of active * threads. * * @param fraction the fraction of processing threads to remain active. This * number is in range [0, 1] */ public void updateActiveThreadsFraction(double fraction) { checkState(fraction >= 0 && fraction <= 1); int numActiveThreads = (int) (numProcessingThreads * fraction); if (LOG.isInfoEnabled()) { LOG.info("updateActiveThreadsFraction: updating the number of active " + "threads to " + numActiveThreads); } activeThreadsPermit.setMaxPermits(numActiveThreads); }
activeThreadsPermit.setMaxPermits(activeThreadsPermit.availablePermits() * numComputeThreads / numProcessingThreads); numProcessingThreads = numComputeThreads; metaPartitionManager.getNumInMemoryPartitions() + " partitions in memory and " + activeThreadsPermit.availablePermits() + " active threads");
new AdjustableSemaphore(maxOpenRequestsPerWorker), -1); Pair<AdjustableSemaphore, Integer> temp = perWorkerOpenRequestMap.putIfAbsent(destTaskId, pair); boolean shouldSend = openRequestPermit.tryAcquire(); boolean shouldCache = false; while (!shouldSend) { shouldSend = openRequestPermit.tryAcquire(); if (shouldSend) { break; shouldSend = openRequestPermit.tryAcquire(); if (!shouldSend) { aggregateUnsentRequests.getAndIncrement();
openRequestPermit.release(); } else if (LOG.isDebugEnabled()) { LOG.debug("messageAckReceived: ACK of resume received from " + taskId + if (compareTimestamps(timestamp, pair.getRight()) > 0) { pair.setRight(timestamp); openRequestPermit.setMaxPermits(credit); } else if (LOG.isDebugEnabled()) { LOG.debug("messageAckReceived: received out-of-order messages." +
/** * Notify the out-of-core engine that a processing (input/compute) thread has * finished. */ public void processingThreadFinish() { activeThreadsPermit.release(); }
/** * Notify the out-of-core engine that a processing (input/compute) thread has * started. */ public void processingThreadStart() { try { activeThreadsPermit.acquire(); } catch (InterruptedException e) { LOG.error("processingThreadStart: exception while acquiring a permit to" + " start the processing thread!"); throw new IllegalStateException(e); } }
.append(sorted.get(i).getKey()).append(" (credit=") .append(perWorkerOpenRequestMap.get(sorted.get(i).getKey()) .getKey().getMaxPermits()) .append("), ");
if (!openRequestPermit.tryAcquire()) { requestDeque.offerFirst(request); break;
this.activeThreadsPermit = new AdjustableSemaphore(numProcessingThreads); this.superstep = BspService.INPUT_SUPERSTEP; this.resetDone = false;
/** * Process a resume signal came from a given worker * * @param clientId id of the worker that sent the signal * @param credit the credit value sent along with the resume signal * @param requestId timestamp (request id) of the resume signal */ public void processResumeSignal(int clientId, short credit, long requestId) { int timestamp = (int) (requestId & 0xFFFF); if (LOG.isDebugEnabled()) { LOG.debug("processResumeSignal: resume signal from " + clientId + " with timestamp=" + timestamp); } MutablePair<AdjustableSemaphore, Integer> pair = (MutablePair<AdjustableSemaphore, Integer>) perWorkerOpenRequestMap.get(clientId); synchronized (pair) { if (compareTimestamps(timestamp, pair.getRight()) > 0) { pair.setRight(timestamp); pair.getLeft().setMaxPermits(credit); } else if (LOG.isDebugEnabled()) { LOG.debug("processResumeSignal: received out-of-order messages. " + "Received timestamp=" + timestamp + " and current timestamp=" + pair.getRight()); } } trySendCachedRequests(clientId); } }