MCPcopy Create free account
hub / github.com/grpc/grpc-java / CachingRlsLbClient

Class CachingRlsLbClient

rls/src/main/java/io/grpc/rls/CachingRlsLbClient.java:87–1104  ·  view source on GitHub ↗

A CachingRlsLbClient is a core implementation of RLS loadbalancer supports dynamic request routing by fetching the decision from route lookup server. Every single request is routed by the server's decision. To reduce the performance penalty, LruCache is used.

Source from the content-addressed store, hash-verified

85 * the server's decision. To reduce the performance penalty, {@link LruCache} is used.
86 */
87@ThreadSafe
88final class CachingRlsLbClient {
89
90 private static final Converter<RouteLookupRequest, io.grpc.lookup.v1.RouteLookupRequest>
91 REQUEST_CONVERTER = new RlsProtoConverters.RouteLookupRequestConverter().reverse();
92 private static final Converter<RouteLookupResponse, io.grpc.lookup.v1.RouteLookupResponse>
93 RESPONSE_CONVERTER = new RouteLookupResponseConverter().reverse();
94 public static final long MIN_EVICTION_TIME_DELTA_NANOS = TimeUnit.SECONDS.toNanos(5);
95 public static final int BYTES_PER_CHAR = 2;
96 public static final int STRING_OVERHEAD_BYTES = 38;
97 /** Minimum bytes for a Java Object. */
98 public static final int OBJ_OVERHEAD_B = 16;
99
100 private static final LongCounterMetricInstrument DEFAULT_TARGET_PICKS_COUNTER;
101 private static final LongCounterMetricInstrument TARGET_PICKS_COUNTER;
102 private static final LongCounterMetricInstrument FAILED_PICKS_COUNTER;
103 private static final LongGaugeMetricInstrument CACHE_ENTRIES_GAUGE;
104 private static final LongGaugeMetricInstrument CACHE_SIZE_GAUGE;
105 private final Registration gaugeRegistration;
106 private final String metricsInstanceUuid = UUID.randomUUID().toString();
107
108 // All cache status changes (pending, backoff, success) must be under this lock
109 private final Object lock = new Object();
110 // LRU cache based on access order (BACKOFF and actual data will be here)
111 @GuardedBy("lock")
112 private final RlsAsyncLruCache linkedHashLruCache;
113 private final Future<?> periodicCleaner;
114 // any RPC on the fly will cached in this map
115 @GuardedBy("lock")
116 private final Map<RouteLookupRequestKey, PendingCacheEntry> pendingCallCache = new HashMap<>();
117
118 private final ScheduledExecutorService scheduledExecutorService;
119 private final Ticker ticker;
120 private final Throttler throttler;
121
122 private final LbPolicyConfiguration lbPolicyConfig;
123 private final BackoffPolicy.Provider backoffProvider;
124 private final long maxAgeNanos;
125 private final long staleAgeNanos;
126 private final long callTimeoutNanos;
127
128 private final RlsLbHelper helper;
129 private final ManagedChannel rlsChannel;
130 private final RouteLookupServiceStub rlsStub;
131 private final RlsPicker rlsPicker;
132 private final ResolvedAddressFactory childLbResolvedAddressFactory;
133 @GuardedBy("lock")
134 private final RefCountedChildPolicyWrapperFactory refCountedChildPolicyWrapperFactory;
135 private final ChannelLogger logger;
136 private final ChildPolicyWrapper fallbackChildPolicyWrapper;
137
138 static {
139 MetricInstrumentRegistry metricInstrumentRegistry
140 = MetricInstrumentRegistry.getDefaultRegistry();
141 DEFAULT_TARGET_PICKS_COUNTER = metricInstrumentRegistry.registerLongCounter(
142 "grpc.lb.rls.default_target_picks",
143 "EXPERIMENTAL. Number of LB picks sent to the default target", "{pick}",
144 Arrays.asList("grpc.target", "grpc.lb.rls.server_target",

Callers

nothing calls this directly

Calls 7

getDefaultRegistryMethod · 0.95
registerLongCounterMethod · 0.80
asListMethod · 0.80
registerLongGaugeMethod · 0.80
emptyListMethod · 0.80
toStringMethod · 0.45
ofMethod · 0.45

Tested by

no test coverage detected