-
-
Notifications
You must be signed in to change notification settings - Fork 74
Cache do not update per second one day #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Do you test with the latest SNAPSHOT code? Can you give a complete example of what you are trying with the cache and what you would expect, like a test case? Since you use the code that is currently in progress, it might be unfinished or a bug. Maybe its also a wrong assumption of the functionality. |
Yes, use 2.8-SNAPSHOT, we used 4 months, and it's right util this time. I execute jstack, there saw only 2 cache2k-scheduler threads, then I restart the application and saw another cache2k-loader- thread. Note: cache refresh after write 1 second. |
It would be better to use a released version. The SNAPSHOT might have varying quality. Still, I am not sure what you are doing. Can you give me detailed information and steps how to reproduce your observations? |
Below is the simplest test code. import java.time.Duration; import java.time.LocalDateTime; import java.util.concurrent.TimeUnit; import org.cache2k.Cache; import org.cache2k.Cache2kBuilder; import org.cache2k.expiry.RefreshAheadPolicy; import org.junit.Test; /** * Cache refresh failed one day. https://github.com/cache2k/cache2k/issues/195 * * @author javalover123 * @date 2022/10/28 */ public class Cache2kRefreshTest { static Cache<String, LocalDateTime> TIME_CACHE = new Cache2kBuilder<String, LocalDateTime>() { }.refreshAheadPolicy(new AutoRefreshPolicy<>()) .expireAfterWrite(1, TimeUnit.SECONDS) .timerLag(Duration.ofMillis(300)) .loader((key) -> LocalDateTime.now()) .build(); public static class AutoRefreshPolicy<K, V, T> implements RefreshAheadPolicy<K, V, T> { @Override public long refreshAheadTime(Context<T> ctx) { return ctx.getExpiryTime(); } @Override public int requiredHits(Context<T> ctx) { return 0; } } @Test public void refresh() throws InterruptedException { for (int i = 1; i <= 100000; i++) { final LocalDateTime now = LocalDateTime.now(); final LocalDateTime cacheTime = TIME_CACHE.get(""); if (cacheTime.plusSeconds(3).isBefore(now)) { System.err.println(now + ",refresh error," + cacheTime); } Thread.sleep(100); } System.out.println(LocalDateTime.now() + ",refresh done"); } } |
Thanks for the update! How many refresh errors do you get? |
I think the cause of your problem is, that by default cache2k is expiring (or refreshing) timer based and execution of timer events will always lag behind. This behavior is saving resources. With typical cache expiry times around 5 minutes, it does not matter if an update happens one second later. For the purpose of testing you can add |
Not lag minutes, but hours. For example 15:00(today) execute TIME_CACHE.get("") get yesterday. PS: I update the test code. |
I execute jstack per 0.5 second, there is a same thread "cache2k-loader-_Cache2kRefreshTest.CLINIT-22-dk-1" #30, and not saw the thread when cache not update. |
What is the git revision of cache2k you are using? What Java runtime version you are using? |
git revision is 437c58c1ceb0cacaa9d2d282ad702e6aeed3e19d Run on windows, jdk is below. |
Ok, I will investigate. In the code I am in the middle of some restructuring, however, I was held up by other projects since May. If this is blocking your project maybe consider using the latest released final version. Before the next release I will do some more changes around the Anyhow, it is great that you test with the latest code base and give feedback. That catches potential problems early on. |
Do I assume correctly that if you start the application its sometimes not working at all? If so, approximately, out of how many starts it does fail? My strategy is to add a configuration similar to yours to our test and run these tests many times to make sure there is no spurious problem within the initialization procedures. |
Run 4 months, just happened once only. |
Are you using ECC memory on the servers? |
Maybe is non-ECC memory. Get-WmiObject Win32_PhysicalMemory | Select-Object -Property PSComputerName, DeviceLocator, Manufacturer, PartNumber, @{label = "Size/GB" ; Expression = {$_.capacity / 1GB}}, Speed, datawidth, totalwidth, @{label = "ECC" ; Expression = { if ( $_.totalwidth -gt $_.datawidth ) { "$($_.DeviceLocator) is ECC memory type" } else { "$($_.DeviceLocator) is non-ECC Memory Type" } } } | Out-GridView |
This might be the issue since you saw it only once in 4 month of operation. |
If this is the case and there is no other information we might close the issue. |
I execute jstack per 0.5 second, there is a same thread "cache2k-loader-_Cache2kRefreshTest.CLINIT-22-dk-1" #30, and not saw the thread when cache not update. |
Cache do not update per second one day, and there no thread name starts with cache2k-loader-
The text was updated successfully, but these errors were encountered: