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

Keep active ciphers at the front and add metrics #12

Merged
merged 2 commits into from
Dec 19, 2018
Merged

Conversation

fortuna
Copy link

@fortuna fortuna commented Dec 18, 2018

With this change the active ciphers will be kept at the front of the cipher list. This way the search latency is proportional to the number of active ciphers, rather than total number of ciphers. In practice only a fraction of ciphers in a server is active at any given time.

With this change I no longer shuffle the ciphers.

Benchmark is about the same:

BenchmarkTCPFindCipher-12    	    1000	   1334343 ns/op	  126177 B/op	    1706 allocs/op
BenchmarkUDPUnpack-12        	    2000	    909550 ns/op	  125926 B/op	    1702 allocs/op

The time to find the cipher can be tracked with shadowsocks_time_to_cipher_ms. Example:

# HELP shadowsocks_time_to_cipher_ms Time needed to find the cipher
# TYPE shadowsocks_time_to_cipher_ms summary
shadowsocks_time_to_cipher_ms{access_key="user-0",location="",proto="tcp",status="OK",quantile="0.5"} 0.136696
shadowsocks_time_to_cipher_ms{access_key="user-0",location="",proto="tcp",status="OK",quantile="0.9"} 0.226364
shadowsocks_time_to_cipher_ms{access_key="user-0",location="",proto="tcp",status="OK",quantile="0.99"} 0.226364
shadowsocks_time_to_cipher_ms_sum{access_key="user-0",location="",proto="tcp",status="OK"} 0.6387840000000001
shadowsocks_time_to_cipher_ms_count{access_key="user-0",location="",proto="tcp",status="OK"} 4
shadowsocks_time_to_cipher_ms{access_key="user-1",location="",proto="tcp",status="OK",quantile="0.5"} 0.138071
shadowsocks_time_to_cipher_ms{access_key="user-1",location="",proto="tcp",status="OK",quantile="0.9"} 0.225075
shadowsocks_time_to_cipher_ms{access_key="user-1",location="",proto="tcp",status="OK",quantile="0.99"} 0.302819
shadowsocks_time_to_cipher_ms_sum{access_key="user-1",location="",proto="tcp",status="OK"} 1.6076639999999998
shadowsocks_time_to_cipher_ms_count{access_key="user-1",location="",proto="tcp",status="OK"} 11

@fortuna fortuna self-assigned this Dec 18, 2018
@fortuna fortuna requested a review from trevj December 18, 2018 21:38
@fortuna fortuna changed the title Keep active ciphers at the front Keep active ciphers at the front and add metrics Dec 18, 2018
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