579 if tests_to_http_lock:
580 locked_shards.append(("tests_to_http_lock", tests_to_http_lock))
580 # Put a ceiling on the number of locked shards, so that we
581 # don't hammer the servers too badly. For now we will
582 # arbitrarily limit this to no more than a quarter of all workers.
583 max_locked_shards = max(math.ceil(int(self._options.child_processes) / 4.0), 1)
584 dirs_per_new_shard = math.ceil(len(locked_shards) / max_locked_shards * 1.0)
585 new_locked_shards = []
586 i = 1
587 j = 1
588 tests = []
589 while locked_shards:
590 shard = locked_shards.pop()
591 tests.extend(shard[1])
592 i += 1
593 if i > dirs_per_new_shard:
594 new_locked_shards.append(('locked_shard_%d' % j, tests))
595 i = 0
596 j += 1
597 tests = []
598 if tests:
599 new_locked_shards.append(('locked_shard_%d' % j, tests))
600 locked_shards = new_locked_shards