keyman performance improvements
Background
Working with the keyman orchestration system and found a few issues that I think should be addressed.
Issues
Key distribution isn't fair When you publish the same key to the same platform twice, it gets added to the pool multiple times and receives extra traffic. Not common but should be prevented.
# Without duplicate check, key appears twice in pool
keypub.publish("ghp_abc123", "github_rest")
keypub.publish("ghp_abc123", "github_rest") # duplicate
# Output: fresh_keys["github_rest"] = ["ghp_abc123", "ghp_abc123"]
Typo in exception class
WaitKeyTimeout has tiemout_seconds instead of timeout_seconds. Found this while debugging.
Missing documentation
- No clear docs on how many Redis connections keyman creates
- The directory could benefit from a directory-specific README.
What I'm planning to fix
- Add a duplicate check in
publish_key()- simpleif key not in listbefore appending - Fix the typo
- Document the connection pooling situation
- Improve docstrings
- Write a proper README for the keyman directory
Testing
Should be straightforward. Publish the same key twice and make sure it only appears once in the pool
as noted in #3414, i think the duplicate publishing was intentionally a feature because probabiltically weihted key use was something that was used previously but isnt anymore. if we want to remove this, it may be good to store keys as a set, ehich gaurantees they are unique
In that case, I can open up a new PR that stores the keys in a set. Or even better, should I open a new issue that we can mark as "good first issue" for others to pick up?
Based on the title, your existing, closed PR for this may update docs and a typo, so let's maybe merge those two pieces since they exist already (i assume). Then we can just use this issue as the "duplicate key prevention" issue I guess
In general combining multiple problems into one issue isn't ideal, but i'm also guilty of doing that myself when the additional fixes are small (like the docs and typos)
Re-opened PR #3414 . The new PR now only deals with typo fix and doc changes. Removed the duplicate key addition check code from that PR @MoralCode