Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCK switch to ShardedLock #138

Merged
merged 1 commit into from
Oct 15, 2024
Merged

PCK switch to ShardedLock #138

merged 1 commit into from
Oct 15, 2024

Conversation

dahlend
Copy link
Collaborator

@dahlend dahlend commented Oct 15, 2024

SPK was switched to sharded lock a while ago, but PCK was missed. This is a significant performance improvement for multi-thread earth orientation queries.

@fmasci
Copy link
Collaborator

fmasci commented Oct 15, 2024 via email

@dahlend
Copy link
Collaborator Author

dahlend commented Oct 15, 2024

Spice kernels are stored in memory shared between threads. Having multiple threads access the same memory can lead to race conditions, where you may make a change to memory while some other thread is reading it. the RwLock, (Read/Write lock) method means you have a Mutex (basically a thread safe flag), which indicates that the chunk of memory you are using is either in read or write mode. If it is in read mode, all the threads can safely read simultaneously. If it is in write mode, only 1 thread may use it at once.

The standard implementation of the read write lock in rust assumes about an equal usage of read and write, however for our needs we typically write once (or very infrequently), and only read from that point forward. This is a very one-sided usage, and the assumptions which the RwLock operate under are not ideal, leading to poorer performance. I tested several alternate implementations about 6 months ago and settled on the ShardedLock, which does the same thing, but the implementation is more friendly for the read heavy conditions we experience. It was about an order of magnitude speedup when using many threads in contention for the spice memory.

@dahlend
Copy link
Collaborator Author

dahlend commented Oct 15, 2024

I unfortunately only put the change in the the SPK reader, which is where we need it the most, but forgot to change the PCK reader. This PR just updates that.

@dahlend dahlend merged commit 9220369 into main Oct 15, 2024
2 checks passed
@dahlend dahlend deleted the pck_rwlock branch October 15, 2024 16:20
@fmasci
Copy link
Collaborator

fmasci commented Oct 15, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants