Golang AppEngine Goon库本地内存限制

huangapple go评论84阅读模式
英文:

golang appengine goon lib local memory limits

问题

goon本地内存缓存是否有默认限制,以防止内存填满并导致内存溢出异常?我可以看到有一个公共的FlushLocalCache方法,但我没有在库中看到它被使用。如果该库不自动清除本地内存缓存,有什么好的方案可以确保不过度使用内存大小?

英文:

Are there any default limits on the goon local memory cache, so it won't fill up the memory and cause some sort of our of memory exception? I can see there's a public FlushLocalCache method but I don't see it being used anywhere within the library. If the lib doesn't auto take care of clearing out the local memory cache, what would be a good schema to use to ensure you don't over use your memory size?

答案1

得分: 1

goon的文档中提到,本地缓存是按请求进行的,这意味着它只会在当前请求的持续时间内累积数据。

实际上,本地缓存是Go对象的一部分,该对象应该是从appengine上下文创建的,而该上下文是从请求本身创建的(参见NewGoon和FromContext函数)。一旦请求被处理完毕,相应的缓存数据就可以进行垃圾回收。

因此,实际上并没有限制本地缓存可以累积的内存量,但在实践中是无害的,因为单个请求不应该处理大量的数据。然而,如果请求在向缓存中添加许多记录时发生循环,就可能出现病态情况。

这种方法的一个缺点是,如果缓存的数据没有被使用,它往往会生成无用的垃圾。但它可能简化一些代码。例如,基于引用数据的重复验证所生成的往返可以通过优化而消除额外的复杂性。

请注意,如果本地缓存跨越多个请求,将很难定义适当的缓存失效策略,同时仍然保持对数据一致性的控制。

英文:

The documentation of goon says the local cache is per-request, meaning that it will only accumulate data for the duration of the current request.

Actually the local cache is part of a Goon object, which is supposed to be created from an appengine context, created from the request itself (see NewGoon and FromContext functions). The corresponding cached data can be garbage collected once the request has been processed.

So nothing actually limits the memory that can be accumulated in the local cache, but in practice it is harmless, because a single request is not supposed to deal with a massive amount of data. The pathological case of a request looping while adding many records in the cache is possible though.

One of the drawback of this approach is it tends to generate useless garbage if the cached data are not used. But it may simplify some code. For instance, the roundtrips generated by repetitive validations based on referential data can be optimized away without additional complexity.

Note that if the local cache spanned over several requests, it would be difficult to define a proper cache invalidation strategy while still maintaining control on the data consistency.

huangapple
  • 本文由 发表于 2015年4月22日 16:37:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/29792001.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定