【问题标题】:Is gc.log writing asynchronous? safe to put gc.log on NFS mount?gc.log 是异步写入的吗?将 gc.log 安全地放在 NFS 挂载上?
【发布时间】:2014-11-21 23:52:43
【问题描述】:

我多次听说将 gc.log 放在 NFS 卷上是一个糟糕的主意,因为它可能会导致 gc 暂停时间更长。现在的jdk(8u25)还是这样吗?

【问题讨论】:

  • 我不明白为什么这会改变。在不需要异步的最常见情况下,使 gc 日志记录异步对性能不利。如果您真的非常想知道:1) 测试它或 2) 阅读源代码。

标签: java performance garbage-collection nfs


【解决方案1】:

所以我检查了 - 它不是异步的,而是使用常规的 fopen/fwrite。 Relevant code from jdk8u:

gcLogFileStream::gcLogFileStream(const char* file_name) {
  _cur_file_num = 0;
  _bytes_written = 0L;
  _file_name = make_log_name(file_name, NULL);

  // gc log file rotation
  if (UseGCLogFileRotation && NumberOfGCLogFiles > 1) {
    char tempbuf[FILENAMEBUFLEN];
    jio_snprintf(tempbuf, sizeof(tempbuf), "%s.%d" CURRENTAPPX, _file_name, _cur_file_num);
    _file = fopen(tempbuf, "w");
  } else {
    _file = fopen(_file_name, "w");
  }
  if (_file != NULL) {
    _need_close = true;
    dump_loggc_header();
  } else {
    warning("Cannot open file %s due to %s\n", _file_name, strerror(errno));
    _need_close = false;
  }
}

void gcLogFileStream::write(const char* s, size_t len) {
  if (_file != NULL) {
    size_t count = fwrite(s, 1, len, _file);
    _bytes_written += count;
  }
  update_position(s, len);
}

【讨论】:

    猜你喜欢
    • 2014-01-14
    • 2023-02-26
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 2015-12-29
    相关资源
    最近更新 更多