简体   繁体   English

编年史队列大小确定

[英]Chronicle queue size determination

If we need to limit total size of chronicle queue to let say 1GB or 10GB.如果我们需要限制编年史队列的总大小,比如说 1GB 或 10GB。 What would be the best way to do it ?最好的方法是什么?

We store buffers as bytes so I was trying to calculate total size just by summing buffer sizes but looks like there is no easy way to correlate this with actual size of queue.我们将缓冲区存储为字节,因此我试图仅通过对缓冲区大小求和来计算总大小,但似乎没有简单的方法可以将其与队列的实际大小相关联。 One way is to calculate total directory size using file utils every 5 minutes or so but that would be error prone if there is huge data in the interval and it may overflow一种方法是每 5 分钟左右使用文件 utils 计算总目录大小,但如果间隔中有大量数据并且可能会溢出,则很容易出错

you would have to add up the size of each cq4 files你必须把每个 cq4 文件的大小加起来

the writePosition gives you the length of each cq4 file in bytes writePosition 以字节为单位为您提供每个 cq4 文件的长度

public class Example {

    public static void main(String[] args) throws FileNotFoundException {
        SingleChronicleQueue q = SingleChronicleQueueBuilder.builder().path("tmp").build();

        ExcerptAppender appender = q.createAppender();

        try (DocumentContext dc = appender.writingDocument()) {
            long l = dc.wire().bytes().writePosition();
            dc.wire().write().text("lastx");
        }

       DumpQueueMain.dump(q.fileAbsolutePath());

    }
}

outputs the following输出以下内容

--- !!meta-data #binary
header: !SCQStore {
  writePosition: [
    131328,
    564049465049088
  ],
  indexing: !SCQSIndexing {
    indexCount: !short 8192,
    indexSpacing: 64,
    index2Index: 184,
    lastIndex: 64
  }
}

# position: 184, header: -1
--- !!meta-data #binary
index2index: [
  # length: 8192, used: 1
  65760 # truncated trailing zeros
]
# position: 65760, header: -1
--- !!meta-data #binary
index: [
  # length: 8192, used: 1
  131328 # truncated trailing zeros
]
# position: 131328, header: 0
--- !!data #binary
"": lastx

...
# 83754737 bytes remaining

--- !!meta-data #binary
header: !STStore {
  wireType: !WireType BINARY_LIGHT,
  recovery: !TimedStoreRecovery {
    timeStamp: 0
  },
  metadata: !SCQMeta {
    roll: !SCQSRoll { length: !int 86400000, format: yyyyMMdd, epoch: 0 },
    deltaCheckpointInterval: 64,
    sourceId: 0
  }
}

# position: 225, header: 0
--- !!data #binary
listing.highestCycle: 17780

# position: 264, header: 1
--- !!data #binary
listing.lowestCycle: 17780

# position: 304, header: 2
--- !!data #binary
listing.modCount: 1

# position: 336, header: 3
--- !!data #binary
chronicle.write.lock: -9223372036854775808

# position: 376, header: 4
--- !!data #binary
chronicle.lastIndexReplicated: -1

# position: 432, header: 5
--- !!data #binary
chronicle.lastAcknowledgedIndexReplicated: -1

...
# 65044 bytes remaining

when the length of the .cq4 file is defined by当 .cq4 文件的长度由

writePosition: [
    131328,
     ....
  ],

in other words 131328 bytes换句话说131328字节

The chronicle queue files roll based on time not file size.编年史队列文件根据时间而不是文件大小滚动。 Why do you wish to limit the size of the .cq4 file ?为什么要限制 .cq4 文件的大小?

If you wish you could roll the queue file every Minute by changing the roll cycle.如果您希望可以通过更改滚动周期,每分钟滚动一次队列文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM