Understand benchmark implementation and metrics
masterThe benchmark script evaluates lock performance based on the following parameters:
- Implementation: The locking mechanism used (
redis_lockvsnative). - Lock duration: The artificial amount of time the script sleeps while holding the lock before releasing it.
- Concurrency: The number of processes simultaneously attempting to acquire the same lock.
- Acquires: The total number of successful lock acquisitions recorded.
- Avg/Min/Max: The average, minimum, and maximum number of acquisitions per process.
Key Performance Observations
- Single Client (No Contention): The
redis_lockimplementation is slightly slower than thenativeimplementation due to overhead in the lock releasing script. - Two Clients (Contention): The
nativeimplementation loses throughput because its acquiring routine uses awhile True: sleep(0.1)loop. It also tends to favor the first client, as the waiting client's sleep interval is relatively large. - High Concurrency or High Duration: Under high contention or long lock durations, the
nativeimplementation becomes unpredictable. Some clients may fail to acquire the lock entirely (indicated by aMinvalue of0), while others may acquire it disproportionately often (indicated by a highMaxvalue).