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

fix: remove the auth_zones lock and count up/down queries in a common way #1160

Closed
wants to merge 2 commits into from

Conversation

sakateka
Copy link
Contributor

The lock field in the auth_zones struct is used only to protect the up/down query counters. My understanding is that the auth_zones struct is only constructed when there are no other threads, so there are no possibilities for concurrent access. However, concurrent modifications still occur in auth_zones.c, specifically during query counting. By adopting a common approach to tracking up/down queries, similar to that used for other server statistics, we can simplify the codebase and eliminate the need for locking mechanisms.

I benchmarked the performance of this patch using the following configuration to effectively disable cache:

...
msg-cache-size: 2b
msg-cache-slabs: 1
rrset-cache-size: 2b
rrset-cache-slabs: 1
key-cache-size: 2b
key-cache-slabs: 1
neg-cache-size: 2b
...

Results:
Before

Read 9M.qerires, got 9000000 queries
qps: 137430
...
qps: 137043
overall time: 15.0001 sec
0(NOERROR): 2070494 replies
average qps: 138032

After

Read 9M.qerires, got 9000000 queries
qps: 159759
qps: 161599
...
qps: 166993
qps: 157685
overall time: 15 sec
0(NOERROR): 2451661 replies
average qps: 163444

… way

The lock field in the auth_zones struct is used only to protect the
up/down query counters. My understanding is that the auth_zones struct
is only constructed when there are no other threads, so there are no
possibilities for concurrent access. However, concurrent modifications
still occur in auth_zones.c, specifically during query counting.
By adopting a common approach to tracking up/down queries, similar to
that used for other server statistics, we can simplify the codebase
and eliminate the need for locking mechanisms.

I benchmarked the performance of this patch using the following configuration
to effectively disable cache:

...
        msg-cache-size: 2b
        msg-cache-slabs: 1
        rrset-cache-size: 2b
        rrset-cache-slabs: 1
        key-cache-size: 2b
        key-cache-slabs: 1
        neg-cache-size: 2b
...

Results:
Before

Read 9M.qerires, got 9000000 queries
qps: 137430
...
qps: 137043
overall time: 	15.0001 sec
0(NOERROR): 	2070494 replies
average qps: 	138032

After

Read 9M.qerires, got 9000000 queries
qps: 159759
qps: 161599
...
qps: 166993
qps: 157685
overall time: 	15 sec
0(NOERROR): 	2451661 replies
average qps: 	163444
@sakateka sakateka force-pushed the lock-free-auth_zones branch from 8dfb2f2 to d5033ea Compare October 29, 2024 13:45
@sakateka
Copy link
Contributor Author

This patch can be implemented without removing the auth_zones lock.
If there is any doubt about removing this lock, I can return it.
But as far as I can see, this lock is not used anywhere in the current code to protect ztree for writing.

@sakateka
Copy link
Contributor Author

If you don't like big lock removal, I create another PR that reworks counters but doesn't touch auth_zones' lock.
#1169

@sakateka
Copy link
Contributor Author

Closed in favor of #1169

@sakateka sakateka closed this Nov 15, 2024
@sakateka sakateka deleted the lock-free-auth_zones branch November 15, 2024 16:49
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.

1 participant