javascript
有关Spring缓存性能的更多信息
這是我們最后一篇關于Spring的緩存抽象的文章的后續文章 。
作為工程師,您可以通過了解所使用的某些工具的內部知識來獲得寶貴的經驗。 了解工具的行為有助于您在做出設計選擇時變得更加成熟。 在這篇文章中,我們描述了一個基準測試實驗和結果,這些結果將幫助您了解Spring的內置緩存注釋。
看一下以下兩種方法:
@Cacheable (value = "time" , key = "#p0.concat(#p1)" ) public long annotationWithSpel(String dummy1, String dummy2) { "#p0.concat(#p1)" annotationWithSpel(String dummy1, String dummy2) { return System.currentTimeMillis(); } System.currentTimeMillis(); } @Cacheable (value = "time" ) public long annotationBased(String dummy1, String dummy2) { @Cacheable (value = annotationBased(String dummy1, String dummy2) { return System.currentTimeMillis(); } System.currentTimeMillis(); }在這里,我們有兩種非常相似的方法,每種方法都使用Spring Cache的內置@Cacheable注釋進行注釋。 第一個包含使用Spring Expression Language編寫的表達式。 該表達式用于配置如何使用方法參數計算緩存鍵。 第二個依賴于Spring的默認行為,即“所有方法參數均視為鍵”。 實際上,以上兩種方法實際上都導致完全相同的外部行為。
我們進行了一些基準測試,從而可以評估其性能:
Benchmark Mode Cnt Score Error Units CacheBenchmark.annotationBased avgt 5 271.975 ± 11.586 ns/op CacheBenchmark.spel avgt 5 1196.744 ± 93.765 ns/op CacheBenchmark.manual avgt 5 16.325 ± 0.856 ns/op CacheBenchmark.nocache avgt 5 40.142 ± 4.012 ns/op事實證明,具有手動配置的緩存的方法運行速度慢4.4倍! 事后看來,由于間接費用,這種結果似乎是合理的。 Spring框架必須解析任意復雜的表達式,并且在此計算中消耗了一些周期。
我們為什么要寫這個故事? 好 -
您應該檢查您的代碼庫,并進行檢查或審核。 杰蒂森(Jettison)也在其中一些實例中獲得了性能提升。 您很可能在某些實例中也手動配置了緩存鍵。 請記住,這與Spring Cache默認為您提供的行為完全相同。 絕對的雙贏局面!
翻譯自: https://www.javacodegeeks.com/2019/04/more-about-spring-cache-performance.html
總結
以上是生活随笔為你收集整理的有关Spring缓存性能的更多信息的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电脑主题windows7(电脑主题壁纸)
- 下一篇: 条形码扫描器电脑版(条形码扫描器手机版)