缓存测试_测试缓存的注意事项

缓存测试

Software development teams often use in-memory caches to improve performance. They want to speed up access to, or reduce load on, a backing store (database, file system, etc.) by keeping some or all of the data in memory.

软件开发团队经常使用内存缓存来提高性能。 他们希望通过将部分或全部数据保留在内存中来加快对后备存储(数据库,文件系统等)的访问或减轻其负担。

You should implement a system in the simplest way. Then after performance testing, you should optimize only when necessary. The reason for this is that performance optimizations make code more complex and may introduce defects. Often these defects are subtle, difficult to find and expensive to fix.

您应该以最简单的方式实现系统。 然后,在进行性能测试后,仅应在必要时进行优化。 原因是性能优化使代码更复杂,并可能引入缺陷。 这些缺陷通常很细微,难以发现且修复成本很高。

Developers often do not consider thorough testing of caching optimizations. They consider a cache as an implementation detail rather than functionality requiring testing.

开发人员通常不考虑对缓存优化进行彻底的测试。 他们将缓存视为实现细节,而不是需要测试的功能。

A write-through cache approach writes to both the cache and the backing store at the same time. A service can use this approach when it is the single source of the backing store data in a system.

直写式高速缓存方法同时写入高速缓存和后备存储。 当服务是系统中后备存储数据的唯一来源时,可以使用此方法。

I recommend that you consider the following items when designing, implementing, and testing caches. I have seen live defects in almost all of these areas.

我建议您在设计,实施和测试缓存时考虑以下各项。 我在几乎所有这些领域都看到过现场缺陷。

You need to have enough memory for the cache. What is the size of each object in the cacheWhat is the maximum number of objects in the cacheDo you have enough memory on your machine or JVM when the cache is fullWhat happens when the cache is full and you need to add one more object to it/p>

您需要有足够的内存用于缓存。 缓存中每个对象的大小是多少缓存中的最大对象数是多少缓存已满时,您的计算机或JVM上是否有足够的内存当缓存已满并且您需要向其添加一个对象时会发生什么

How is the cache initializedIf it’s initialized when your application starts, how long does that take when you cache the maximum number of objectsCan your application serve requests during initializationIf objects are cached as requests are made, is the response time of the cache miss or write-through transaction acceptable/p>

缓存如何初始化如果在应用程序启动时进行了初始化,那么在缓存最大数量的对象时需要花费多长时间您的应用程序可以在初始化期间处理请求吗如果在发出请求时缓存对象,那么缓存未命中或直写事务的响应时间是否可以接受

Verify that the cache is used. If the cache is not write-through you can request the data, then change the data in the backing store, then request it again and it should not change. Or you could request some data to cause it to be cached, then make the backing store inaccessible, and request the same data.

验证是否使用了缓存。 如果缓存不是直写,则可以请求数据,然后在后备存储中更改数据,然后再次请求,并且该数据不应更改。 或者,您可以请求一些数据以使其被缓存,然后使后备存储无法访问,并请求相同的数据。

What happens when the backing store is unavailableA request for data that is cached should probably return successfully. A request for data that is not cached should probably return an error or degraded functionality.

没有后备存储时会发生什么对缓存数据的请求可能应该成功返回。 对于未缓存的数据的请求可能应该返回错误或功能降级。

If the cache is not write-through (some other process writes to the backing store), you may have to refresh the data periodically or on demand. Is it acceptable for the cache to be different than the backing storeHow long is it acceptableVerify that the data is refreshed properly.

如果缓存不是直写式(某些其他进程写入后备存储),则可能必须定期或按需刷新数据。 缓存与后备存储不同可以接受吗可以接受多长时间验证是否正确刷新了数据。

Will it hold all of the objects or only some of themWhich object do you evict when the cache is full and you need to replace the itemWhat eviction scheme do you use – Least Recently Used (LRU), Least Frequently Used (LFU) or First In First Out (FIFO) or do entries expire after a periodVerify the eviction scheme.

它会容纳所有对象还是仅容纳其中一些对象当缓存已满并且需要替换该项目时,您将驱逐哪个对象您使用哪种驱逐方案–最近使用最少(LRU),最不经常使用(LFU)或先进先出(FIFO)或条目会在一段时间后过期验证驱逐方案。

In addition, for testing and/or production support, you may need the ability to evict individual objects and/or all objects from the cache. One use case for this is you may want to fix some bad data in the database for a particular customer, then clear the cache just for that customer.

另外,为了进行测试和/或生产支持,您可能需要能够从缓存中逐出单个对象和/或所有对象。 一种使用情况是,您可能想为特定客户修复数据库中的一些不良数据,然后仅为该客户清除缓存。

Finally, verify you get the performance improvement you expect. Test it using production traffic patterns. When the cache is live in production, monitor the size of the cache and the hit ratio (when a request finds the object in the cache) to determine if the cache works properly. You may need to make improvements.

最后,确认您获得了预期的性能改进。 使用生产流量模式对其进行测试。 当缓存处于生产环境中时,监视缓存的大小和命中率(当请求在缓存中找到对象时),以确定缓存是否正常工作。 您可能需要进行改进。

I hope you agree with me that caches have a lot of functionality that deserves proper design, implementation and testing.

我希望您同意我的观点,缓存具有许多值得适当设计,实施和测试的功能。

翻译自: https://www.experts-exchange.com/articles/17601/Considerations-for-Testing-a-Cache.html

缓存测试

文章知识点与官方知识档案匹配,可进一步学习相关知识Java技能树使用JDBC操作数据库数据库操作91322 人正在系统学习中 相关资源:实例讲解分布式缓存软件Memcached的Java客户端使用-其它代码类…

来源:cunchi8090

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年6月18日
下一篇 2020年6月18日

相关推荐