You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shenyu.apache.org by ttttangzhen <ta...@foxmail.com> on 2021/05/17 07:47:30 UTC

回复: There may be a wrong way to use guava cache

in org.apache.shenyu.plugin.apache.dubbo.cache.ApplicationConfigCache and ApplicationConfigCache in other RPC plugin
------------------------------------------------------------------------------------------------
private final LoadingCache<> cache = CacheBuilder.newBuilder()                                                                                        
.maximumWeight(maxCount)                                                                                        
.weigher( (string, referenceConfig) -> getSize())                                                                                        
.build();

private int getSize() {      
return (int) cache.size();
}
------------------------------------------------------------------------------------------------

Here, weight is used to control the total capacity of guava cache, but the weight of each cache use getSize,it represents the total number of items cached when a piece of data is cached.
I think there may be wrong usage here, If we use weights, the weights should represent the size of each piece of data, so here should be replaced by the number of bars to control the total capacity

------------------ 原始邮件 ------------------发件人:                                                                                                                        "dev"                                                                                    <zh...@apache.org>;发送时间: 2021年5月17日(星期一) 下午3:43收件人: "dev"<de...@shenyu.apache.org>;主题: Re: There may be a wrong way to use guava cacheHi Zhen,Please send the raw text to this mail list.--Zhang YonglunApache ShenYu (Incubating)Apache ShardingSpherettttangzhen <28...@qq.com> 于2021年5月17日周一 下午3:37写道:> in org.apache.shenyu.plugin.apache.dubbo.cache.ApplicationConfigCache and> ApplicationConfigCache in other RPC plugin>>> ------------------------------------------------------------------------------------------------> private final LoadingCache<&gt; cache => CacheBuilder.newBuilder()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;>> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;> .build();> private int getSize() {&nbsp;&nbsp;&nbsp;> &nbsp;&nbsp;&nbsp; return (int) cache.size();> }>> ------------------------------------------------------------------------------------------------>> Here, weight is used to control the total capacity of guava cache, but the> weight of each cache use getSize,it represents the total number of items> cached when a piece of data is cached.> I think there may be wrong usage here, If we use weights, the weights> should represent the size of each piece of data, so here should be replaced> by the number of bars to control the total capacity

回复: There may be a wrong way to use guava cache

Posted by ttttangzhen <ta...@foxmail.com>.
Ok, I will fix it soon.




------------------&nbsp;原始邮件&nbsp;------------------
发件人:                                                                                                                        "dev"                                                                                    <xiaoyu@apache.org&gt;;
发送时间:&nbsp;2021年5月17日(星期一) 下午4:50
收件人:&nbsp;"dev"<dev@shenyu.apache.org&gt;;

主题:&nbsp;Re: There may be a wrong way to use guava cache



Hi,

I checked the API for Guava , You are right , this is a bug,&nbsp;&nbsp; Can you fix
it.?



ttttangzhen <tangzhen1996@foxmail.com&gt; 于2021年5月17日周一 下午4:47写道:

&gt; maximumWeight(maxCount)&nbsp; mean max total weight,
&gt; but the method getSize return weight may cause that when the number of
&gt; caches increases to 316, adding a new cache will delete many caches
&gt; I think maximumSize should be used here instead of maximumWeight.
&gt;
&gt; if you think so, I will fix it
&gt;
&gt;
&gt; ------------------ 原始邮件 ------------------发件人:
&gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "dev"
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <xiaoyu@apache.org&gt;;发送时间: 2021年5月17日(星期一)
&gt; 下午3:52收件人: "dev"<dev@shenyu.apache.org&gt;;主题: Re: There may be a wrong way
&gt; to use guava cacheHi ,maxCount is capacity of guava cache,others
&gt; thinks?ttttangzhen <tangzhen1996@foxmail.com&gt; 于2021年5月17日周一 下午3:48写道:&gt; in
&gt; org.apache.shenyu.plugin.apache.dubbo.cache.ApplicationConfigCache and&gt;
&gt; ApplicationConfigCache in other RPC plugin&gt;&gt;
&gt; ------------------------------------------------------------------------------------------------&gt;
&gt; private final LoadingCache<&gt; cache = CacheBuilder.newBuilder()&gt;&gt;
&gt; .maximumWeight(maxCount)&gt;&gt; .weigher( (string, referenceConfig) -&gt;
&gt; getSize())&gt;&gt; .build();&gt;&gt; private int getSize() {&gt; return (int)
&gt; cache.size();&gt; }&gt;&gt;
&gt; ------------------------------------------------------------------------------------------------&gt;&gt;
&gt; Here, weight is used to control the total capacity of guava cache, but the&gt;
&gt; weight of each cache use getSize,it represents the total number of items&gt;
&gt; cached when a piece of data is cached.&gt; I think there may be wrong usage
&gt; here, If we use weights, the weights&gt; should represent the size of each
&gt; piece of data, so here should be replaced&gt; by the number of bars to control
&gt; the total capacity

Re: There may be a wrong way to use guava cache

Posted by Yu Xiao <xi...@apache.org>.
Hi,

I checked the API for Guava , You are right , this is a bug,   Can you fix
it.?



ttttangzhen <ta...@foxmail.com> 于2021年5月17日周一 下午4:47写道:

> maximumWeight(maxCount)  mean max total weight,
> but the method getSize return weight may cause that when the number of
> caches increases to 316, adding a new cache will delete many caches
> I think maximumSize should be used here instead of maximumWeight.
>
> if you think so, I will fix it
>
>
> ------------------ 原始邮件 ------------------发件人:
>
>                 "dev"
>                               <xi...@apache.org>;发送时间: 2021年5月17日(星期一)
> 下午3:52收件人: "dev"<de...@shenyu.apache.org>;主题: Re: There may be a wrong way
> to use guava cacheHi ,maxCount is capacity of guava cache,others
> thinks?ttttangzhen <ta...@foxmail.com> 于2021年5月17日周一 下午3:48写道:> in
> org.apache.shenyu.plugin.apache.dubbo.cache.ApplicationConfigCache and>
> ApplicationConfigCache in other RPC plugin>>
> ------------------------------------------------------------------------------------------------>
> private final LoadingCache<> cache = CacheBuilder.newBuilder()>>
> .maximumWeight(maxCount)>> .weigher( (string, referenceConfig) ->
> getSize())>> .build();>> private int getSize() {> return (int)
> cache.size();> }>>
> ------------------------------------------------------------------------------------------------>>
> Here, weight is used to control the total capacity of guava cache, but the>
> weight of each cache use getSize,it represents the total number of items>
> cached when a piece of data is cached.> I think there may be wrong usage
> here, If we use weights, the weights> should represent the size of each
> piece of data, so here should be replaced> by the number of bars to control
> the total capacity

回复: There may be a wrong way to use guava cache

Posted by ttttangzhen <ta...@foxmail.com>.
maximumWeight(maxCount)  mean max total weight, 
but the method getSize return weight may cause that when the number of caches increases to 316, adding a new cache will delete many caches
I think maximumSize should be used here instead of maximumWeight.

if you think so, I will fix it


------------------ 原始邮件 ------------------发件人:                                                                                                                        "dev"                                                                                    <xi...@apache.org>;发送时间: 2021年5月17日(星期一) 下午3:52收件人: "dev"<de...@shenyu.apache.org>;主题: Re: There may be a wrong way to use guava cacheHi ,maxCount is capacity of guava cache,others thinks?ttttangzhen <ta...@foxmail.com> 于2021年5月17日周一 下午3:48写道:> in org.apache.shenyu.plugin.apache.dubbo.cache.ApplicationConfigCache and> ApplicationConfigCache in other RPC plugin>> ------------------------------------------------------------------------------------------------> private final LoadingCache<> cache = CacheBuilder.newBuilder()>> .maximumWeight(maxCount)>> .weigher( (string, referenceConfig) -> getSize())>> .build();>> private int getSize() {> return (int) cache.size();> }>> ------------------------------------------------------------------------------------------------>> Here, weight is used to control the total capacity of guava cache, but the> weight of each cache use getSize,it represents the total number of items> cached when a piece of data is cached.> I think there may be wrong usage here, If we use weights, the weights> should represent the size of each piece of data, so here should be replaced> by the number of bars to control the total capacity

Re: There may be a wrong way to use guava cache

Posted by Yu Xiao <xi...@apache.org>.
Hi ,

maxCount is capacity of guava cache,others thinks?

ttttangzhen <ta...@foxmail.com> 于2021年5月17日周一 下午3:48写道:

> in org.apache.shenyu.plugin.apache.dubbo.cache.ApplicationConfigCache and
> ApplicationConfigCache in other RPC plugin
>
> ------------------------------------------------------------------------------------------------
> private final LoadingCache<> cache = CacheBuilder.newBuilder()
>
> .maximumWeight(maxCount)
>
> .weigher( (string, referenceConfig) -> getSize())
>
> .build();
>
> private int getSize() {
> return (int) cache.size();
> }
>
> ------------------------------------------------------------------------------------------------
>
> Here, weight is used to control the total capacity of guava cache, but the
> weight of each cache use getSize,it represents the total number of items
> cached when a piece of data is cached.
> I think there may be wrong usage here, If we use weights, the weights
> should represent the size of each piece of data, so here should be replaced
> by the number of bars to control the total capacity
>
> ------------------ 原始邮件 ------------------发件人:
>
>                 "dev"
>                               <zh...@apache.org>;发送时间:
> 2021年5月17日(星期一) 下午3:43收件人: "dev"<de...@shenyu.apache.org>;主题: Re: There may
> be a wrong way to use guava cacheHi Zhen,Please send the raw text to this
> mail list.--Zhang YonglunApache ShenYu (Incubating)Apache
> ShardingSpherettttangzhen <28...@qq.com> 于2021年5月17日周一 下午3:37写道:> in
> org.apache.shenyu.plugin.apache.dubbo.cache.ApplicationConfigCache and>
> ApplicationConfigCache in other RPC plugin>>>
> ------------------------------------------------------------------------------------------------>
> private final LoadingCache<&gt; cache =>
> CacheBuilder.newBuilder()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;>>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs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>>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;>
> .build();> private int getSize() {&nbsp;&nbsp;&nbsp;> &nbsp;&nbsp;&nbsp;
> return (int) cache.size();> }>>
> ------------------------------------------------------------------------------------------------>>
> Here, weight is used to control the total capacity of guava cache, but the>
> weight of each cache use getSize,it represents the total number of items>
> cached when a piece of data is cached.> I think there may be wrong usage
> here, If we use weights, the weights> should represent the size of each
> piece of data, so here should be replaced> by the number of bars to control
> the total capacity