You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2021/07/13 07:40:15 UTC

[iotdb] branch stirngmem created (now 036d273)

This is an automated email from the ASF dual-hosted git repository.

haonan pushed a change to branch stirngmem
in repository https://gitbox.apache.org/repos/asf/iotdb.git.


      at 036d273  Using cached pool to reduce the String memory size in TsFileResourse

This branch includes the following new commits:

     new 036d273  Using cached pool to reduce the String memory size in TsFileResourse

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[iotdb] 01/01: Using cached pool to reduce the String memory size in TsFileResourse

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

haonan pushed a commit to branch stirngmem
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 036d273067c720638eaa350b384cbc49f6579e3f
Author: Haonan <hh...@outlook.com>
AuthorDate: Tue Jul 13 14:10:59 2021 +0800

    Using cached pool to reduce the String memory size in TsFileResourse
---
 .../iotdb/db/engine/storagegroup/timeindex/DeviceTimeIndex.java     | 6 +++++-
 .../iotdb/db/engine/storagegroup/timeindex/FileTimeIndex.java       | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/DeviceTimeIndex.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/DeviceTimeIndex.java
index c0556a9..36d42e9 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/DeviceTimeIndex.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/DeviceTimeIndex.java
@@ -88,13 +88,17 @@ public class DeviceTimeIndex implements ITimeIndex {
       ReadWriteIOUtils.write(endTimes[i], outputStream);
     }
 
+    Map<String, Integer> stringMemoryReducedMap = new ConcurrentHashMap<>();
     for (Entry<String, Integer> stringIntegerEntry : deviceToIndex.entrySet()) {
       String deviceName = stringIntegerEntry.getKey();
-      deviceName = cachedDevicePool.computeIfAbsent(deviceName, k -> k);
       int index = stringIntegerEntry.getValue();
+      // To reduce the String number in memory,
+      // use the deviceId from cached pool
+      stringMemoryReducedMap.put(cachedDevicePool.computeIfAbsent(deviceName, k -> k), index);
       ReadWriteIOUtils.write(deviceName, outputStream);
       ReadWriteIOUtils.write(index, outputStream);
     }
+    deviceToIndex = stringMemoryReducedMap;
   }
 
   @Override
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/FileTimeIndex.java b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/FileTimeIndex.java
index d8baafe..1cd35d6 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/FileTimeIndex.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/storagegroup/timeindex/FileTimeIndex.java
@@ -66,12 +66,16 @@ public class FileTimeIndex implements ITimeIndex {
   @Override
   public void serialize(OutputStream outputStream) throws IOException {
     ReadWriteIOUtils.write(devices.size(), outputStream);
+    Set<String> stringMemoryReducedSet = new ConcurrentSet<>();
     for (String device : devices) {
-      device = cachedDevicePool.computeIfAbsent(device, k -> k);
+      // To reduce the String number in memory,
+      // use the deviceId from cached pool
+      stringMemoryReducedSet.add(cachedDevicePool.computeIfAbsent(device, k -> k));
       ReadWriteIOUtils.write(device, outputStream);
     }
     ReadWriteIOUtils.write(startTime, outputStream);
     ReadWriteIOUtils.write(endTime, outputStream);
+    devices = stringMemoryReducedSet;
   }
 
   @Override