Add short-term host/contact caching for high-QPS domain mutations

After investigating common domain create/update command usage
patterns by registrars, we noticed that it is frequent for a
given registrar to reuse both hosts (using a standardized set of
nameservers) as well as contacts (e.g. for privacy/proxy
services). With these usage patterns, potential per-registrar
throughput during high volume scenarios (i.e. first moments of
General Availability) suffers from hitting hot keys in Datastore.

The solution, implemented in this CL, is to add short-term
in-memory caching for contacts and hosts, analogous to how we are
already caching Registry and Registrar entities.  These new
cached paths are only used inside domain flows to determine
existence and deleted/pending delete status of contacts and
hosts. This is a potential loss of transactional consistency, but
in practice it's hard to imagine this having negative effects, as
contacts or hosts that are in use cannot be deleted, and caching
would primarily affect widely used contacts and hosts.

Note that this caching can be turned on or off through a
configuration option, and by default would be off. We'd only want
it on when we really needed it, i.e. during a big launch.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=187093378
This commit is contained in:
mcilwain
2018-03-06 19:05:20 -05:00
committed by jianglai
parent cd9bd35a08
commit ce136f9285
13 changed files with 461 additions and 16 deletions
@@ -1018,6 +1018,10 @@ public final class RegistryConfig {
* asynchronously fails the delete). Without this delay, the mapreduce might have started before
* the domain flow committed, and could potentially miss the reference.
*
* <p>If you are using EPP resource caching (eppResourceCachingEnabled in YAML), then this
* duration should also be longer than that cache duration (eppResourceCachingSeconds).
*
* @see google.registry.config.RegistryConfigSettings.Caching
* @see google.registry.flows.async.AsyncFlowEnqueuer
*/
@Provides
@@ -1324,6 +1328,27 @@ public final class RegistryConfig {
return CONFIG_SETTINGS.get().caching.staticPremiumListMaxCachedEntries;
}
public static boolean isEppResourceCachingEnabled() {
return CONFIG_SETTINGS.get().caching.eppResourceCachingEnabled;
}
@VisibleForTesting
public static void overrideIsEppResourceCachingEnabledForTesting(boolean enabled) {
CONFIG_SETTINGS.get().caching.eppResourceCachingEnabled = enabled;
}
/**
* Returns the amount of time an EPP resource or key should be cached in memory before expiring.
*/
public static Duration getEppResourceCachingDuration() {
return Duration.standardSeconds(CONFIG_SETTINGS.get().caching.eppResourceCachingSeconds);
}
/** Returns the maximum number of EPP resources and keys to keep in in-memory cache. */
public static int getEppResourceMaxCachedEntries() {
return CONFIG_SETTINGS.get().caching.eppResourceMaxCachedEntries;
}
/** Returns the email address that outgoing emails from the app are sent from. */
public static String getGSuiteOutgoingEmailAddress() {
return CONFIG_SETTINGS.get().gSuite.outgoingEmailAddress;
@@ -110,6 +110,9 @@ public class RegistryConfigSettings {
public int domainLabelCachingSeconds;
public int singletonCachePersistSeconds;
public int staticPremiumListMaxCachedEntries;
public boolean eppResourceCachingEnabled;
public int eppResourceCachingSeconds;
public int eppResourceMaxCachedEntries;
}
/** Configuration for ICANN monthly reporting. */
@@ -141,6 +141,28 @@ caching:
# premium price entries that exist.
staticPremiumListMaxCachedEntries: 200000
# Whether to enable caching of EPP resource entities and keys. Enabling this
# caching allows for much higher domain create/update throughput when hosts
# and/or contacts are being frequently used (which is commonly the case).
# However, this may introduce transactional inconsistencies, such as allowing
# hosts or contacts to be used that are actually deleted (though in practice
# this will only happen for non-widely-used entities). Only set this to true
# if you need the performance, i.e. if you need >10 domain mutations per
# frequently used contact or host. This situation is typically caused by
# registrars reusing the same contact/host across many operations, e.g. a
# privacy/proxy contact or a common host pointing to a registrar-run
# nameserver.
eppResourceCachingEnabled: false
# Length of time that EPP resource entities and keys are cached in memory
# before expiring.
eppResourceCachingSeconds: 60
# The maximum number of EPP resource entities and keys to cache in memory.
# LoadingCache evicts rarely-used keys first, so in practice this does not
# have to be very large to achieve the vast majority of possible gains.
eppResourceMaxCachedEntries: 500
oAuth:
# OAuth scopes to detect on access tokens. Superset of requiredOauthScopes.
availableOauthScopes:
@@ -18,6 +18,8 @@ caching:
domainLabelCachingSeconds: 0
singletonCachePersistSeconds: 0
staticPremiumListMaxCachedEntries: 50
eppResourceCachingEnabled: true
eppResourceCachingSeconds: 0
braintree:
merchantAccountIdsMap: