Add buffering to LocalSnapshotStore 91/82491/2
authorTomas Cere <tomas.cere@pantheon.tech>
Tue, 4 Jun 2019 13:32:20 +0000 (15:32 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 11 Jun 2019 22:32:43 +0000 (00:32 +0200)
These improve snapshot save/load load times by around 15-20%
on my environment.

Change-Id: I67236f7e97f519993031d462c947588004857c33
Signed-off-by: Tomas Cere <tomas.cere@pantheon.tech>
(cherry picked from commit aec4fefef94890a35f9e637575f29d91b7b7504f)

opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/persistence/LocalSnapshotStore.java

index 893e4e2c39fbcfaef09d913f6b01a5815e0b4590..7ac1492ee3779fbf965a0cdf42d74fb1d95f796f 100644 (file)
@@ -19,6 +19,7 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.io.ByteStreams;
 import com.typesafe.config.Config;
 import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -133,7 +134,7 @@ public class LocalSnapshotStore extends SnapshotStore {
     }
 
     private Object deserialize(final File file) throws IOException {
-        try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(file))) {
+        try (ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)))) {
             return in.readObject();
         } catch (ClassNotFoundException e) {
             throw new IOException("Error loading snapshot file " + file, e);
@@ -171,7 +172,7 @@ public class LocalSnapshotStore extends SnapshotStore {
 
         LOG.debug("Saving to temp file: {}", temp);
 
-        try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(temp))) {
+        try (ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(temp)))) {
             out.writeObject(snapshot);
         } catch (IOException e) {
             LOG.error("Error saving snapshot file {}. Deleting file..", temp, e);