You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by "nfsantos (via GitHub)" <gi...@apache.org> on 2024/09/16 14:57:57 UTC
[PR] OAK-11121 - indexing-job: print thread CPU, GC and memory usage statistics periodically during indexing download [jackrabbit-oak]
nfsantos opened a new pull request, #1721:
URL: https://github.com/apache/jackrabbit-oak/pull/1721
(no comment)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11121 - indexing-job: print thread CPU, GC and memory usage statistics periodically during indexing download [jackrabbit-oak]
Posted by "nfsantos (via GitHub)" <gi...@apache.org>.
nfsantos merged PR #1721:
URL: https://github.com/apache/jackrabbit-oak/pull/1721
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11121 - indexing-job: print thread CPU, GC and memory usage statistics periodically during indexing download [jackrabbit-oak]
Posted by "nfsantos (via GitHub)" <gi...@apache.org>.
nfsantos commented on code in PR #1721:
URL: https://github.com/apache/jackrabbit-oak/pull/1721#discussion_r1763330278
##########
oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/ThreadMonitor.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined;
+
+import org.apache.jackrabbit.guava.common.base.Stopwatch;
+import org.apache.jackrabbit.oak.plugins.index.FormattingUtils;
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.ThreadMXBean;
+import java.util.Comparator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * Keeps track of a list of threads and prints statistics of CPU usage of the threads. It also prints statistics
+ * of memory usage and garbage collections
+ */
+public class ThreadMonitor {
+ /**
+ * Thread factory that registers all new threads with a given thread monitor. This can be passed to an Executor, so
+ * that all of its threads will be monitored, which may be simpler than manually registering each individual thread.
+ */
+ public static class AutoRegisteringThreadFactory implements ThreadFactory {
+ private final ThreadMonitor threadMonitor;
+ private final ThreadFactory delegate;
+
+ /**
+ * @param threadMonitor The thread monitor where to register new threads.
+ * @param delegate A thread factory to create new threads.
+ */
+ public AutoRegisteringThreadFactory(ThreadMonitor threadMonitor, ThreadFactory delegate) {
+ this.threadMonitor = threadMonitor;
+ this.delegate = delegate;
+ }
+
+ /**
+ * Uses Executors.defaultThreadFactory() to create new threads.
+ *
+ * @param threadMonitor The thread monitor where to register new threads.
+ */
+ public AutoRegisteringThreadFactory(ThreadMonitor threadMonitor) {
+ this.threadMonitor = threadMonitor;
+ this.delegate = Executors.defaultThreadFactory();
+ }
+
+ @Override
+ public Thread newThread(@NotNull Runnable r) {
+ Thread t = delegate.newThread(r);
+ threadMonitor.registerThread(t);
+ return t;
+ }
+ }
+
+ private static final Logger LOG = LoggerFactory.getLogger(ThreadMonitor.class);
+ private final CopyOnWriteArraySet<Thread> threadIds = new CopyOnWriteArraySet<>();
+
+ private final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
+ private final List<GarbageCollectorMXBean> gcMxBeans = ManagementFactory.getGarbageCollectorMXBeans();
+ private final MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();
+
+ private final Stopwatch stopwatch = Stopwatch.createUnstarted();
+
+ public void start() {
+ stopwatch.start();
+ }
+
+ public void registerThread(Thread thread) {
+ threadIds.add(thread);
+ }
+
+ public void unregisterThread(Thread thread) {
+ threadIds.remove(thread);
+ }
+
+ public void printStatistics() {
+ printStatistics("Thread/Memory report");
+ }
+
+ public void printStatistics(String heading) {
+ long timeSinceStartMillis = stopwatch.elapsed().toMillis();
+
+ StringBuilder sb = new StringBuilder(heading + ". Time since start of monitoring: " + stopwatch + "\n");
+
+ // Memory usage
+ sb.append(String.format(" Heap memory usage: %s, Non-heap memory usage: %s\n",
+ memoryMxBean.getHeapMemoryUsage(), memoryMxBean.getNonHeapMemoryUsage()));
+
+ // Garbage collection
+ for (GarbageCollectorMXBean gcBean : gcMxBeans) {
+ sb.append(String.format(" Collector: %s, collectionCount: %d, collectionTime: %d ms (%.2f%%)\n",
+ gcBean.getName(), gcBean.getCollectionCount(), gcBean.getCollectionTime(),
+ FormattingUtils.safeComputePercentage(gcBean.getCollectionTime(), timeSinceStartMillis))
+ );
+ }
+
+ // Thread CPU usage
+ threadIds.stream().sorted(Comparator.comparing(Thread::getId)).forEach(thread -> {
+ long threadCpuTimeMillis = threadMXBean.getThreadCpuTime(thread.getId()) / 1_000_000;
+ long threadUserTimeMillis = threadMXBean.getThreadUserTime(thread.getId()) / 1_000_000;
+ double threadCpuTimePercentage = FormattingUtils.safeComputePercentage(threadCpuTimeMillis, timeSinceStartMillis);
+ double threadUserTimePercentage = FormattingUtils.safeComputePercentage(threadUserTimeMillis, timeSinceStartMillis);
+ sb.append(String.format(" Thread %d/%s - cpuTime: %d (%.2f%%), userTime: %d (%.2f%%)\n",
Review Comment:
I prefer to have the thread name at the start, reads more naturally. But I added some basic formatting to align the fields. Have a look at the updated table in the PR description, it is more readable now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11121 - indexing-job: print thread CPU, GC and memory usage statistics periodically during indexing download [jackrabbit-oak]
Posted by "nfsantos (via GitHub)" <gi...@apache.org>.
nfsantos commented on code in PR #1721:
URL: https://github.com/apache/jackrabbit-oak/pull/1721#discussion_r1763328964
##########
oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/ThreadMonitor.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined;
+
+import org.apache.jackrabbit.guava.common.base.Stopwatch;
+import org.apache.jackrabbit.oak.plugins.index.FormattingUtils;
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.ThreadMXBean;
+import java.util.Comparator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * Keeps track of a list of threads and prints statistics of CPU usage of the threads. It also prints statistics
+ * of memory usage and garbage collections
+ */
+public class ThreadMonitor {
+ /**
+ * Thread factory that registers all new threads with a given thread monitor. This can be passed to an Executor, so
+ * that all of its threads will be monitored, which may be simpler than manually registering each individual thread.
+ */
+ public static class AutoRegisteringThreadFactory implements ThreadFactory {
Review Comment:
Moved the inner static class to the end.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11121 - indexing-job: print thread CPU, GC and memory usage statistics periodically during indexing download [jackrabbit-oak]
Posted by "nfsantos (via GitHub)" <gi...@apache.org>.
nfsantos commented on code in PR #1721:
URL: https://github.com/apache/jackrabbit-oak/pull/1721#discussion_r1763327987
##########
oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/ThreadMonitor.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined;
+
+import org.apache.jackrabbit.guava.common.base.Stopwatch;
+import org.apache.jackrabbit.oak.plugins.index.FormattingUtils;
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.ThreadMXBean;
+import java.util.Comparator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * Keeps track of a list of threads and prints statistics of CPU usage of the threads. It also prints statistics
+ * of memory usage and garbage collections
+ */
+public class ThreadMonitor {
+ /**
+ * Thread factory that registers all new threads with a given thread monitor. This can be passed to an Executor, so
+ * that all of its threads will be monitored, which may be simpler than manually registering each individual thread.
+ */
+ public static class AutoRegisteringThreadFactory implements ThreadFactory {
+ private final ThreadMonitor threadMonitor;
+ private final ThreadFactory delegate;
+
+ /**
+ * @param threadMonitor The thread monitor where to register new threads.
+ * @param delegate A thread factory to create new threads.
+ */
+ public AutoRegisteringThreadFactory(ThreadMonitor threadMonitor, ThreadFactory delegate) {
+ this.threadMonitor = threadMonitor;
+ this.delegate = delegate;
+ }
+
+ /**
+ * Uses Executors.defaultThreadFactory() to create new threads.
+ *
+ * @param threadMonitor The thread monitor where to register new threads.
+ */
+ public AutoRegisteringThreadFactory(ThreadMonitor threadMonitor) {
+ this.threadMonitor = threadMonitor;
+ this.delegate = Executors.defaultThreadFactory();
+ }
+
+ @Override
+ public Thread newThread(@NotNull Runnable r) {
+ Thread t = delegate.newThread(r);
+ threadMonitor.registerThread(t);
+ return t;
+ }
+ }
+
+ private static final Logger LOG = LoggerFactory.getLogger(ThreadMonitor.class);
+ private final CopyOnWriteArraySet<Thread> threadIds = new CopyOnWriteArraySet<>();
+
+ private final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
Review Comment:
Fixed, renamed all to `MX` to be consistent with Java API.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11121 - indexing-job: print thread CPU, GC and memory usage statistics periodically during indexing download [jackrabbit-oak]
Posted by "nfsantos (via GitHub)" <gi...@apache.org>.
nfsantos commented on code in PR #1721:
URL: https://github.com/apache/jackrabbit-oak/pull/1721#discussion_r1763328515
##########
oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/ThreadMonitor.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined;
+
+import org.apache.jackrabbit.guava.common.base.Stopwatch;
+import org.apache.jackrabbit.oak.plugins.index.FormattingUtils;
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.ThreadMXBean;
+import java.util.Comparator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * Keeps track of a list of threads and prints statistics of CPU usage of the threads. It also prints statistics
+ * of memory usage and garbage collections
+ */
+public class ThreadMonitor {
+ /**
+ * Thread factory that registers all new threads with a given thread monitor. This can be passed to an Executor, so
+ * that all of its threads will be monitored, which may be simpler than manually registering each individual thread.
+ */
+ public static class AutoRegisteringThreadFactory implements ThreadFactory {
+ private final ThreadMonitor threadMonitor;
+ private final ThreadFactory delegate;
+
+ /**
+ * @param threadMonitor The thread monitor where to register new threads.
+ * @param delegate A thread factory to create new threads.
+ */
+ public AutoRegisteringThreadFactory(ThreadMonitor threadMonitor, ThreadFactory delegate) {
+ this.threadMonitor = threadMonitor;
+ this.delegate = delegate;
+ }
+
+ /**
+ * Uses Executors.defaultThreadFactory() to create new threads.
+ *
+ * @param threadMonitor The thread monitor where to register new threads.
+ */
+ public AutoRegisteringThreadFactory(ThreadMonitor threadMonitor) {
+ this.threadMonitor = threadMonitor;
+ this.delegate = Executors.defaultThreadFactory();
+ }
+
+ @Override
+ public Thread newThread(@NotNull Runnable r) {
+ Thread t = delegate.newThread(r);
+ threadMonitor.registerThread(t);
+ return t;
+ }
+ }
+
+ private static final Logger LOG = LoggerFactory.getLogger(ThreadMonitor.class);
+ private final CopyOnWriteArraySet<Thread> threadIds = new CopyOnWriteArraySet<>();
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11121 - indexing-job: print thread CPU, GC and memory usage statistics periodically during indexing download [jackrabbit-oak]
Posted by "thomasmueller (via GitHub)" <gi...@apache.org>.
thomasmueller commented on code in PR #1721:
URL: https://github.com/apache/jackrabbit-oak/pull/1721#discussion_r1763158840
##########
oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/ThreadMonitor.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined;
+
+import org.apache.jackrabbit.guava.common.base.Stopwatch;
+import org.apache.jackrabbit.oak.plugins.index.FormattingUtils;
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.ThreadMXBean;
+import java.util.Comparator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * Keeps track of a list of threads and prints statistics of CPU usage of the threads. It also prints statistics
+ * of memory usage and garbage collections
+ */
+public class ThreadMonitor {
+ /**
+ * Thread factory that registers all new threads with a given thread monitor. This can be passed to an Executor, so
+ * that all of its threads will be monitored, which may be simpler than manually registering each individual thread.
+ */
+ public static class AutoRegisteringThreadFactory implements ThreadFactory {
+ private final ThreadMonitor threadMonitor;
+ private final ThreadFactory delegate;
+
+ /**
+ * @param threadMonitor The thread monitor where to register new threads.
+ * @param delegate A thread factory to create new threads.
+ */
+ public AutoRegisteringThreadFactory(ThreadMonitor threadMonitor, ThreadFactory delegate) {
+ this.threadMonitor = threadMonitor;
+ this.delegate = delegate;
+ }
+
+ /**
+ * Uses Executors.defaultThreadFactory() to create new threads.
+ *
+ * @param threadMonitor The thread monitor where to register new threads.
+ */
+ public AutoRegisteringThreadFactory(ThreadMonitor threadMonitor) {
+ this.threadMonitor = threadMonitor;
+ this.delegate = Executors.defaultThreadFactory();
+ }
+
+ @Override
+ public Thread newThread(@NotNull Runnable r) {
+ Thread t = delegate.newThread(r);
+ threadMonitor.registerThread(t);
+ return t;
+ }
+ }
+
+ private static final Logger LOG = LoggerFactory.getLogger(ThreadMonitor.class);
+ private final CopyOnWriteArraySet<Thread> threadIds = new CopyOnWriteArraySet<>();
+
+ private final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
+ private final List<GarbageCollectorMXBean> gcMxBeans = ManagementFactory.getGarbageCollectorMXBeans();
+ private final MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();
+
+ private final Stopwatch stopwatch = Stopwatch.createUnstarted();
+
+ public void start() {
+ stopwatch.start();
+ }
+
+ public void registerThread(Thread thread) {
+ threadIds.add(thread);
+ }
+
+ public void unregisterThread(Thread thread) {
+ threadIds.remove(thread);
+ }
+
+ public void printStatistics() {
+ printStatistics("Thread/Memory report");
+ }
+
+ public void printStatistics(String heading) {
+ long timeSinceStartMillis = stopwatch.elapsed().toMillis();
+
+ StringBuilder sb = new StringBuilder(heading + ". Time since start of monitoring: " + stopwatch + "\n");
+
+ // Memory usage
+ sb.append(String.format(" Heap memory usage: %s, Non-heap memory usage: %s\n",
+ memoryMxBean.getHeapMemoryUsage(), memoryMxBean.getNonHeapMemoryUsage()));
+
+ // Garbage collection
+ for (GarbageCollectorMXBean gcBean : gcMxBeans) {
+ sb.append(String.format(" Collector: %s, collectionCount: %d, collectionTime: %d ms (%.2f%%)\n",
+ gcBean.getName(), gcBean.getCollectionCount(), gcBean.getCollectionTime(),
+ FormattingUtils.safeComputePercentage(gcBean.getCollectionTime(), timeSinceStartMillis))
+ );
+ }
+
+ // Thread CPU usage
+ threadIds.stream().sorted(Comparator.comparing(Thread::getId)).forEach(thread -> {
+ long threadCpuTimeMillis = threadMXBean.getThreadCpuTime(thread.getId()) / 1_000_000;
+ long threadUserTimeMillis = threadMXBean.getThreadUserTime(thread.getId()) / 1_000_000;
+ double threadCpuTimePercentage = FormattingUtils.safeComputePercentage(threadCpuTimeMillis, timeSinceStartMillis);
+ double threadUserTimePercentage = FormattingUtils.safeComputePercentage(threadUserTimeMillis, timeSinceStartMillis);
+ sb.append(String.format(" Thread %d/%s - cpuTime: %d (%.2f%%), userTime: %d (%.2f%%)\n",
Review Comment:
Thread names have a variable size... I usually put the (most) variable size entries at the end of the line. So it would be cpuTime, userTime, thread id / name
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11121 - indexing-job: print thread CPU, GC and memory usage statistics periodically during indexing download [jackrabbit-oak]
Posted by "thomasmueller (via GitHub)" <gi...@apache.org>.
thomasmueller commented on code in PR #1721:
URL: https://github.com/apache/jackrabbit-oak/pull/1721#discussion_r1763112467
##########
oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/ThreadMonitor.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined;
+
+import org.apache.jackrabbit.guava.common.base.Stopwatch;
+import org.apache.jackrabbit.oak.plugins.index.FormattingUtils;
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.ThreadMXBean;
+import java.util.Comparator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * Keeps track of a list of threads and prints statistics of CPU usage of the threads. It also prints statistics
+ * of memory usage and garbage collections
+ */
+public class ThreadMonitor {
+ /**
+ * Thread factory that registers all new threads with a given thread monitor. This can be passed to an Executor, so
+ * that all of its threads will be monitored, which may be simpler than manually registering each individual thread.
+ */
+ public static class AutoRegisteringThreadFactory implements ThreadFactory {
+ private final ThreadMonitor threadMonitor;
+ private final ThreadFactory delegate;
+
+ /**
+ * @param threadMonitor The thread monitor where to register new threads.
+ * @param delegate A thread factory to create new threads.
+ */
+ public AutoRegisteringThreadFactory(ThreadMonitor threadMonitor, ThreadFactory delegate) {
+ this.threadMonitor = threadMonitor;
+ this.delegate = delegate;
+ }
+
+ /**
+ * Uses Executors.defaultThreadFactory() to create new threads.
+ *
+ * @param threadMonitor The thread monitor where to register new threads.
+ */
+ public AutoRegisteringThreadFactory(ThreadMonitor threadMonitor) {
+ this.threadMonitor = threadMonitor;
+ this.delegate = Executors.defaultThreadFactory();
+ }
+
+ @Override
+ public Thread newThread(@NotNull Runnable r) {
+ Thread t = delegate.newThread(r);
+ threadMonitor.registerThread(t);
+ return t;
+ }
+ }
+
+ private static final Logger LOG = LoggerFactory.getLogger(ThreadMonitor.class);
+ private final CopyOnWriteArraySet<Thread> threadIds = new CopyOnWriteArraySet<>();
Review Comment:
I would call it "threads" or "threadList"
##########
oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/ThreadMonitor.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined;
+
+import org.apache.jackrabbit.guava.common.base.Stopwatch;
+import org.apache.jackrabbit.oak.plugins.index.FormattingUtils;
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.ThreadMXBean;
+import java.util.Comparator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * Keeps track of a list of threads and prints statistics of CPU usage of the threads. It also prints statistics
+ * of memory usage and garbage collections
+ */
+public class ThreadMonitor {
+ /**
+ * Thread factory that registers all new threads with a given thread monitor. This can be passed to an Executor, so
+ * that all of its threads will be monitored, which may be simpler than manually registering each individual thread.
+ */
+ public static class AutoRegisteringThreadFactory implements ThreadFactory {
Review Comment:
It's a matter of taste but I usually have static classes at the end (it's easier to verify the fields and that the LOG class matches)
##########
oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/pipelined/ThreadMonitor.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined;
+
+import org.apache.jackrabbit.guava.common.base.Stopwatch;
+import org.apache.jackrabbit.oak.plugins.index.FormattingUtils;
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.ThreadMXBean;
+import java.util.Comparator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * Keeps track of a list of threads and prints statistics of CPU usage of the threads. It also prints statistics
+ * of memory usage and garbage collections
+ */
+public class ThreadMonitor {
+ /**
+ * Thread factory that registers all new threads with a given thread monitor. This can be passed to an Executor, so
+ * that all of its threads will be monitored, which may be simpler than manually registering each individual thread.
+ */
+ public static class AutoRegisteringThreadFactory implements ThreadFactory {
+ private final ThreadMonitor threadMonitor;
+ private final ThreadFactory delegate;
+
+ /**
+ * @param threadMonitor The thread monitor where to register new threads.
+ * @param delegate A thread factory to create new threads.
+ */
+ public AutoRegisteringThreadFactory(ThreadMonitor threadMonitor, ThreadFactory delegate) {
+ this.threadMonitor = threadMonitor;
+ this.delegate = delegate;
+ }
+
+ /**
+ * Uses Executors.defaultThreadFactory() to create new threads.
+ *
+ * @param threadMonitor The thread monitor where to register new threads.
+ */
+ public AutoRegisteringThreadFactory(ThreadMonitor threadMonitor) {
+ this.threadMonitor = threadMonitor;
+ this.delegate = Executors.defaultThreadFactory();
+ }
+
+ @Override
+ public Thread newThread(@NotNull Runnable r) {
+ Thread t = delegate.newThread(r);
+ threadMonitor.registerThread(t);
+ return t;
+ }
+ }
+
+ private static final Logger LOG = LoggerFactory.getLogger(ThreadMonitor.class);
+ private final CopyOnWriteArraySet<Thread> threadIds = new CopyOnWriteArraySet<>();
+
+ private final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
Review Comment:
Here we have "MX" but below "Mx" I would make it consistent (which one is not important to me... I would probably use "MX")
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org