WIP: time work in a UOW, track total and database time. Begin working on session cache. Also need to finish up merge() logic and consider ttl and writeTime.
This commit is contained in:
parent
9bbb6d2371
commit
63c558581b
2 changed files with 41 additions and 4 deletions
27
NOTES
27
NOTES
|
@ -351,3 +351,30 @@ begin:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
public void setPurpose(String purpose) {
|
||||||
|
purpose_ = purpose;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void logTimers(String what) {
|
||||||
|
LOG.info(String.format("UOW(%s) %s %s (total: %.3fµs db: %.3fµs or %2.2f%% of total time)",
|
||||||
|
hashCode(), purpose_, what,
|
||||||
|
elapsedTime_.elapsed(TimeUnit.MICROSECONDS) / 1000.0,
|
||||||
|
databaseTime_.elapsed(TimeUnit.MICROSECONDS) / 1000.0,
|
||||||
|
(elapsedTime_.elapsed(TimeUnit.MICROSECONDS) / databaseTime_.elapsed(TimeUnit.MICROSECONDS)) * 100.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
--- postCommitFunction
|
||||||
|
elapsedTime_.stop();
|
||||||
|
if (purpose_ != null) {
|
||||||
|
logTimers("committed");
|
||||||
|
}
|
||||||
|
|
||||||
|
--- abort
|
||||||
|
elapsedTime_.stop();
|
||||||
|
if (purpose_ != null) {
|
||||||
|
logTimers("aborted");
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ package net.helenus.core;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import com.diffplug.common.base.Errors;
|
import com.diffplug.common.base.Errors;
|
||||||
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.collect.HashBasedTable;
|
import com.google.common.collect.HashBasedTable;
|
||||||
import com.google.common.collect.Table;
|
import com.google.common.collect.Table;
|
||||||
import com.google.common.collect.TreeTraverser;
|
import com.google.common.collect.TreeTraverser;
|
||||||
|
@ -33,6 +34,10 @@ public abstract class AbstractUnitOfWork<E extends Exception> implements UnitOfW
|
||||||
private boolean aborted = false;
|
private boolean aborted = false;
|
||||||
private boolean committed = false;
|
private boolean committed = false;
|
||||||
|
|
||||||
|
private String purpose_;
|
||||||
|
private Stopwatch elapsedTime_;
|
||||||
|
public Stopwatch databaseTime_;
|
||||||
|
|
||||||
// Cache:
|
// Cache:
|
||||||
private final Table<String, String, Object> cache = HashBasedTable.create();
|
private final Table<String, String, Object> cache = HashBasedTable.create();
|
||||||
|
|
||||||
|
@ -86,7 +91,11 @@ public abstract class AbstractUnitOfWork<E extends Exception> implements UnitOfW
|
||||||
// Be sure to check all enclosing UnitOfWork caches as well, we may be nested.
|
// Be sure to check all enclosing UnitOfWork caches as well, we may be nested.
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
return parent.cacheLookup(facets);
|
return parent.cacheLookup(facets);
|
||||||
}
|
} else {
|
||||||
|
Cache<String, Object> cache = session.getSessionCache();
|
||||||
|
|
||||||
|
cache.getIfPresent(key)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -141,9 +150,10 @@ public abstract class AbstractUnitOfWork<E extends Exception> implements UnitOfW
|
||||||
// Merge UOW cache into parent's cache.
|
// Merge UOW cache into parent's cache.
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
parent.mergeCache(cache);
|
parent.mergeCache(cache);
|
||||||
} // else {
|
} else {
|
||||||
// TODO... merge into session cache objects marked cacheable
|
Cache<String, Object> cache = session.getSessionCache();
|
||||||
// }
|
cache.put
|
||||||
|
}
|
||||||
|
|
||||||
// Apply all post-commit functions for
|
// Apply all post-commit functions for
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
|
|
Loading…
Reference in a new issue