Replies: 6 comments 1 reply
-
Hi, if you're referring block handler and fallback in |
Beta Was this translation helpful? Give feedback.
-
Hi Eric
I read that document.
However my code annotation did not work.
I used this code:
public class MemcachedCache extends AbstractValueAdaptingCache {
@OverRide
@SentinelResource(value = MEMCACHED_RESILIENCE_RESOURCE,
fallback = "fallbackForLookup")
public Object lookup(Object key) {
...
// memcached calls
}
Note, the class which shown here MemcachedCache extends
AbstractValueAdaptingCache
which implements Cache interface.
The class MemcachedCache used as implementation of Cacha interface
to support Cachable
spring boot annotation. So the loookup(), get(), put() method invoked
by spring boot framework.
It looks like your proxy pattern with @SentinelResource does not work.
So I decided to use the Sentinel SphU API, (Not sure what SphU stands for , but) I have the
following code now:
public Object lookup(Object key) {
...
Entry entry = null;
try {
entry = SphU.entry(MEMCACHED_RESILIENCE_RESOURCE, EntryType.IN, 1, key);
.....
// access to memcached
// to simulate error:
throw new RuntimeException("error");
} catch (BlockException ex) {
LOGGER.info("lookup, Cuitcut Breaker is open", name);
handleMetrics("lookup", name, key.toString(), memCachedKey, ex);
return null;
} catch (Throwable th) {
Tracer.trace(th);
LOGGER.info("lookup, Remote cache '{}' is not available", name);
ClusterNode createRoleNode = ClusterBuilderSlot.getClusterNode("memcached");
LOGGER.info("lookup, Exception Total Count: {}", createRoleNode.totalException());
LOGGER.info("lookup, Block Request Count: {}", createRoleNode.blockRequest());
LOGGER.info("lookup, DegradeRuleManager.getRules(): {} ",DegradeRuleManager.getRules());
handleMetrics("lookup", name, key.toString(), memCachedKey, th);
return null;
} finally {
if(entry!=null) {
entry.exit();
}
}
Log indicates I have defined 2 DegradeRule
DegradeRule{resource=memcached, grade=1, count=0.6, limitApp=default, timeWindow=20, minRequestAmount=5, slowRatioThreshold=1.0, statIntervalMs=1000},
DegradeRule{resource=memcached, grade=2, count=10.0, limitApp=default, timeWindow=20, minRequestAmount=5, slowRatioThreshold=1.0, statIntervalMs=10}]
Also log shows Exception Total Count: 11 however SphU.entry never throws BlockException exception. It means socket breaker was never opened .
Did I missed something ?
Regards
Vlad
…On Wed, Apr 21, 2021 at 6:38 PM Eric Zhao ***@***.***> wrote:
Hi, if you're referring block handler and fallback in @SentinelResource
annotation, you may refer to
https://github.com/alibaba/Sentinel/tree/master/sentinel-extension/sentinel-annotation-aspectj
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2148 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEW3G6I2W37O35RFQSPMVHDTJ54YNANCNFSM43JWRTMQ>
.
|
Beta Was this translation helpful? Give feedback.
-
Hi Eric
The second approach also does not work
The rules are not charged
The exception counter is increased but BlockException was never thrown
How to properly apply DegradeRule ?
|
Beta Was this translation helpful? Give feedback.
-
Please check whether your class is a Spring bean (Spring AOP proxy requires the instance managed by Spring).
Take rule1 as an example: This indicates: If your QPS > 5, error ratio > 60% in this second, the circuit breaker will be open. Please check whether your requests satisfy the condition. |
Beta Was this translation helpful? Give feedback.
-
Hi Eric, |
Beta Was this translation helpful? Give feedback.
-
I solved the problem by increasing statIntervalMs |
Beta Was this translation helpful? Give feedback.
-
The handler needs to return null object to method caller if exception was caught.
Beta Was this translation helpful? Give feedback.
All reactions