mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 23:29:28 -05:00
perf(cloudfront): stop copying strings for every distribution in the host lookup (#7742)
Every request of every service looked its Host up among the distributions once one existed. For each distribution the lookup built the local delivery host names and cut a substring out of the stored key. 10 distributions added about 4 KB to each request. The lookup now compares the id and the suffix in place and walks the raw keys of the same account.
This commit is contained in:
1 parent
30db535f2e
commit
9822ad5f05
2 files changed
+31
-3
No files matched your search
@@ -578,7 +578,9 @@ public class CloudFrontService implements ServerCertificateReferenceProvider {
|
||||
return null;
|
||||
}
|
||||
String hostname = stripPort(host);
|
||||
List<Distribution> distributions = distStore.scan(k -> true);
|
||||
// Every request gets here once a distribution exists, so this lookup avoids copying strings.
|
||||
String rawPrefix = AccountAwareStorageBackend.rawKey(distStore.accountId(), "");
|
||||
List<Distribution> distributions = distStore.scanRaw(rawKey -> rawKey.startsWith(rawPrefix));
|
||||
for (Distribution dist : distributions) {
|
||||
if (hostname.equalsIgnoreCase(dist.getDomainName())) {
|
||||
return dist;
|
||||
@@ -640,8 +642,11 @@ public class CloudFrontService implements ServerCertificateReferenceProvider {
|
||||
|
||||
/** True when {@code hostname} is the local delivery host of the distribution with this id. */
|
||||
private boolean matchesLocalDeliveryHost(String hostname, String id) {
|
||||
int idLength = id.length();
|
||||
for (String suffix : localDeliverySuffixes) {
|
||||
if (hostname.equalsIgnoreCase(id + suffix)) {
|
||||
if (hostname.length() == idLength + suffix.length()
|
||||
&& hostname.regionMatches(true, 0, id, 0, idLength)
|
||||
&& hostname.regionMatches(true, idLength, suffix, 0, suffix.length())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user