gc.log写异步吗?安全地将gc.log放在NFS挂载上?

时间:2014-11-21 23:52:44

标签: java performance garbage-collection nfs

我多次听说将gc.log放在NFS卷上是个糟糕的主意,因为它可能导致gc暂停时间更长。当前的jdk(8u25)仍然如此吗?

1 个答案:

答案 0 :(得分:4)

所以我检查过 - 它不是异步的,而是使用常规的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);
}