p2phttp uses a LRU for active repositories. It could be improved:
It's possible that a very slow transfer of a lot of data to a rarely used repository will result in the least recently used repository still being in use. It would be good to avoid blocking for a long time waiting for shutdown of that repository.
Here's how: Make activityEnd check if the PerRepoServerState is now idle. If so, move it from its current position in the LRU to the end of the LRU. So popLRU will always yield a state that is inactive. Unless every repo in it is active. --Joey
Hmm, on second thought, this would tend to put the most active repository states at the end of the LRU.
So it would be the next thing popped off the LRU when an active repository state needs to be shut down. Rather than a long-inactive state which has migrated to the middle of the LRU.
It's better to take an inactive state, even one that was recently used, than to wait to shutdown an active state.
So, have a set that holds recently inactivated states. Remove states from it when they become active again, and when they get removed from the main LRU.
Then, if the set is not empty, can just take any state from the set, rather than popLRU, and shutdown will be guaranteed to be fast.
This is only a concern when --jobs is larger than --activerepositories. There have to be enough jobs running to max out --activerepositories. The default is for --activerepositories to be larger than --jobs.
So, any fix for this needs to be simple enough and low resource use enough to justify only improving that edge case. Otherwise forcing --activerepositories to be >= --jobs would be another way to solve this.
You know what... Let's just force that! Then we never have to worry about the shutdown getting stuck waiting on another request to finish.