Skip to content

Commit

Permalink
Set number of test on eviction to max possible value.
Browse files Browse the repository at this point in the history
Before that change if we have more than 3 workers per mnemonic then on every eviction we process 3 worker until the iterator is exhausted and then starting again.

On every `WorkerLifecycleManager` test we run `workerPool.evict()` twice, the  first to collect idle workers and the second to really evict workers. So if we have 4 worker per worker key than in first iteration we will check first 3 workers and on second iteration check 1 last worker and don't evict anything.

PiperOrigin-RevId: 540517544
Change-Id: I3198eed288e1f85ac57f9232e667d87cdf22bb90
  • Loading branch information
Googler authored and copybara-github committed Jun 15, 2023
1 parent 5dc1293 commit e016b4f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ static SimpleWorkerPoolConfig makeConfig(int max) {
// workers for one WorkerKey and can't accommodate a worker for another WorkerKey.
config.setMaxTotal(-1);

// Don't limit number of workers to check during eviction
config.setNumTestsPerEvictionRun(Integer.MAX_VALUE);

// Wait for a worker to become ready when a thread needs one.
config.setBlockWhenExhausted(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,54 @@ public void testGetEvictionCandidates_evictLargestWorkers() throws Exception {
assertThat(workerPool.borrowObject(key).getWorkerId()).isEqualTo(w2.getWorkerId());
}

@Test
public void testGetEvictionCandidates_numberOfWorkersIsMoreThanDeafaultNumTests()
throws Exception {
WorkerPoolImpl workerPool =
new WorkerPoolImpl(
new WorkerPoolConfig(factoryMock, entryList("dummy", 4), emptyEntryList()));
WorkerKey key = createWorkerKey("dummy", fileSystem);
Worker w1 = workerPool.borrowObject(key);
Worker w2 = workerPool.borrowObject(key);
Worker w3 = workerPool.borrowObject(key);
Worker w4 = workerPool.borrowObject(key);
workerPool.returnObject(key, w1);
workerPool.returnObject(key, w2);
workerPool.returnObject(key, w3);
workerPool.returnObject(key, w4);

ImmutableList<WorkerMetric> workerMetrics =
ImmutableList.of(
WorkerMetric.create(
createWorkerProperties(w1.getWorkerId(), 1L, "dummy"),
createWorkerStat(2000),
true),
WorkerMetric.create(
createWorkerProperties(w2.getWorkerId(), 2L, "dummy"),
createWorkerStat(2000),
true),
WorkerMetric.create(
createWorkerProperties(w3.getWorkerId(), 3L, "dummy"),
createWorkerStat(4000),
true),
WorkerMetric.create(
createWorkerProperties(w4.getWorkerId(), 4L, "dummy"),
createWorkerStat(4000),
true));

WorkerOptions options = new WorkerOptions();
options.totalWorkerMemoryLimitMb = 1;
WorkerLifecycleManager manager = new WorkerLifecycleManager(workerPool, options);

assertThat(workerPool.getNumIdlePerKey(key)).isEqualTo(4);
assertThat(workerPool.getNumActive(key)).isEqualTo(0);

manager.evictWorkers(workerMetrics);

assertThat(workerPool.getNumIdlePerKey(key)).isEqualTo(0);
assertThat(workerPool.getNumActive(key)).isEqualTo(0);
}

@Test
public void testGetEvictionCandidates_evictWorkerWithSameMenmonicButDifferentKeys()
throws Exception {
Expand Down

0 comments on commit e016b4f

Please sign in to comment.