From d13d53c8ef0adafaf4f7497eab718026eefc5b66 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Fri, 15 Jun 2018 14:01:07 -0400 Subject: [PATCH] Add a bit of logging --- .../uhn/fhir/jpa/util/ReindexController.java | 5 ++ .../uhn/fhir/jpa/util/HashFunctionTester.java | 47 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/HashFunctionTester.java diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/ReindexController.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/ReindexController.java index b46d0137e75..f1cc3ec861e 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/ReindexController.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/ReindexController.java @@ -83,14 +83,19 @@ public class ReindexController implements IReindexController { break; } } + } catch (Exception e) { + ourLog.error("Failure during reindex", e); + count = -1; } finally { myReindexingLock.release(); } synchronized (this) { if (count == null) { + ourLog.info("Reindex pass complete, no remaining resource to index"); myDontReindexUntil = System.currentTimeMillis() + DateUtils.MILLIS_PER_HOUR; } else { + ourLog.info("Reindex pass complete, {} remaining resource to index", count); myDontReindexUntil = null; } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/HashFunctionTester.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/HashFunctionTester.java new file mode 100644 index 00000000000..2de91e905bf --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/HashFunctionTester.java @@ -0,0 +1,47 @@ +package ca.uhn.fhir.jpa.util; + +import ca.uhn.fhir.util.StopWatch; +import com.google.common.base.Charsets; +import com.google.common.hash.HashFunction; +import com.google.common.hash.Hasher; +import com.google.common.hash.Hashing; +import com.helger.commons.base64.Base64; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.TimeUnit; + +public class HashFunctionTester { + byte[] bytes1 = "ABCDiohseoiey oisegoyi loegsiyosg l".getBytes(Charsets.UTF_8); + byte[] bytes2 = "sepyo pyoiyi fdfff".getBytes(Charsets.UTF_8); + byte[] bytes3 = "us".getBytes(Charsets.UTF_8); + byte[] bytes4 = "f;pspus sgrygliy gfdygfio fdgxylxgfdyfgxloygfxdofgixyl yxxfly3ar3r8a3988".getBytes(Charsets.UTF_8); + + @Test + public void testHashBenchmark() { + + test(Hashing.murmur3_128(), "murmur3_128 "); + test(Hashing.sha256() , "sha256 "); + test(Hashing.sha384() , "sha384 "); + test(Hashing.sha512() , "sha512 "); + + } + + public void test(HashFunction theHashFunction, String theName) { + int loops = 10000; + StopWatch sw = new StopWatch(); + String output = ""; + for (int i = 0; i < loops; i++) { + Hasher hasher = theHashFunction.newHasher(); + hasher.putBytes(bytes1); + hasher.putBytes(bytes2); + hasher.putBytes(bytes3); + hasher.putBytes(bytes4); + output = Base64.encodeBytes(hasher.hash().asBytes()); + } + ourLog.info("{} took {}ms for {} or {}/second to generate {} chars: {}", theName, sw.getMillis(), loops, sw.getThroughput(loops, TimeUnit.SECONDS), output.length(), output); + } + + private static final Logger ourLog = LoggerFactory.getLogger(HashFunctionTester.class); +}