mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -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
@@ -29,6 +29,7 @@ import java.security.KeyPairGenerator;
|
||||
import java.security.spec.ECGenParameterSpec;
|
||||
import java.time.Instant;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -125,6 +126,8 @@ class CloudFrontServiceTest {
|
||||
+ "<Items><Location>US</Location><Location>CA</Location></Items>"
|
||||
+ "</GeoRestriction></Restrictions>";
|
||||
|
||||
private final Map<String, AccountAwareStorageBackend<?>> stores = new HashMap<>();
|
||||
|
||||
private CloudFrontService serviceWithDomainSuffix(String domainSuffix) {
|
||||
return serviceWithDomainSuffix(domainSuffix, "us-east-1");
|
||||
}
|
||||
@@ -135,9 +138,11 @@ class CloudFrontServiceTest {
|
||||
}
|
||||
|
||||
private CloudFrontService serviceWithDomainSuffix(String domainSuffix, String region, String baseUrl) {
|
||||
stores.clear();
|
||||
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
|
||||
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
|
||||
.thenAnswer(invocation -> AccountAwareStorageBackend.inMemory("000000000000"));
|
||||
.thenAnswer(invocation -> stores.computeIfAbsent(invocation.getArgument(1, String.class),
|
||||
ignored -> AccountAwareStorageBackend.inMemory("000000000000")));
|
||||
|
||||
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
|
||||
EmulatorConfig.DnsConfig dnsConfig = Mockito.mock(EmulatorConfig.DnsConfig.class);
|
||||
@@ -473,6 +478,24 @@ class CloudFrontServiceTest {
|
||||
assertNull(service.findByHost("a." + id + ".cloudfront.localhost.floci.io"));
|
||||
assertNull(service.findByHost("EABCDEFGHIJKLM.cloudfront.localhost.floci.io"));
|
||||
assertNull(service.findByHost(".cloudfront.localhost"));
|
||||
|
||||
// The id and the suffix are compared apart, ignoring case.
|
||||
assertEquals(id, service.findByHost(id + ".CLOUDFRONT.LOCALHOST").getId());
|
||||
assertNull(service.findByHost(id + ".cloudfront.localhosx"));
|
||||
assertNull(service.findByHost("X" + id.substring(1) + ".cloudfront.localhost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void findByHostIgnoresADistributionOfAnotherAccount() {
|
||||
CloudFrontService service = serviceWithDomainSuffix("cloudfront.net");
|
||||
Distribution dist = service.createDistribution(distribution(true, List.of()), Map.of());
|
||||
AccountAwareStorageBackend<Distribution> distributions =
|
||||
(AccountAwareStorageBackend<Distribution>) stores.get("cloudfront-distributions.json");
|
||||
distributions.deleteForAccount("000000000000", dist.getId());
|
||||
distributions.putForAccount("111122223333", dist.getId(), dist);
|
||||
|
||||
assertNull(service.findByHost(dist.getDomainName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user