-
Notifications
You must be signed in to change notification settings - Fork 962
ISSUE #931,#907: Add option to track task execution time #932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
bookkeeper-server/src/test/java/org/apache/bookkeeper/test/OpStatTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| /* | ||
| * | ||
| * 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.bookkeeper.test; | ||
|
|
||
| import static org.apache.bookkeeper.bookie.BookKeeperServerStats.SERVER_SCOPE; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import java.util.function.BiConsumer; | ||
| import org.apache.bookkeeper.client.BookKeeper; | ||
| import org.apache.bookkeeper.client.LedgerHandle; | ||
| import org.apache.bookkeeper.util.MathUtils; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Basic tests to verify that stats are being updated as expected. | ||
| */ | ||
| public class OpStatTest extends BookKeeperClusterTestCase { | ||
| private LedgerHandle lh; | ||
|
|
||
| public OpStatTest() { | ||
| super(1); | ||
| } | ||
|
|
||
| @Before | ||
| @Override | ||
| public void setUp() throws Exception { | ||
| super.setUp(); | ||
| lh = bkc.createLedger(1, 1, BookKeeper.DigestType.CRC32, "".getBytes()); | ||
| resetBookieOpLoggers(); | ||
| } | ||
|
|
||
| @After | ||
| @Override | ||
| public void tearDown() throws Exception { | ||
| lh.close(); | ||
| lh = null; | ||
| super.tearDown(); | ||
| } | ||
|
|
||
| private void validateOpStat(TestStatsProvider stats, String path, BiConsumer<Long, Double> f) { | ||
| assertTrue(stats != null); | ||
| TestStatsProvider.TestOpStatsLogger logger = stats.getOpStatsLogger(path); | ||
| assertTrue(logger != null); | ||
| f.accept(logger.getSuccessCount(), logger.getSuccessAverage()); | ||
| } | ||
|
|
||
| private void validateOpStat(TestStatsProvider stats, String paths[], BiConsumer<Long, Double> f) { | ||
| for (String path : paths) { | ||
| validateOpStat(stats, path, f); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testTopLevelBookieWriteCounters() throws Exception { | ||
| long startNanos = MathUtils.nowInNano(); | ||
| lh.addEntry("test".getBytes()); | ||
| long elapsed = MathUtils.elapsedNanos(startNanos); | ||
| TestStatsProvider stats = getStatsProvider(0); | ||
| validateOpStat(stats, new String[]{ | ||
| SERVER_SCOPE + ".ADD_ENTRY", | ||
| SERVER_SCOPE + ".ADD_ENTRY_REQUEST", | ||
| SERVER_SCOPE + ".BookieWriteThreadPool.task_queued", | ||
| SERVER_SCOPE + ".BookieWriteThreadPool.task_execution", | ||
| SERVER_SCOPE + ".CHANNEL_WRITE" | ||
| }, (count, average) -> { | ||
| assertTrue(count == 1); | ||
| assertTrue(average > 0); | ||
| assertTrue(average <= elapsed); | ||
| }); | ||
| validateOpStat(stats, new String[]{ | ||
| SERVER_SCOPE + ".CHANNEL_WRITE" | ||
| }, (count, average) -> { | ||
| assertTrue(count > 0); | ||
| assertTrue(average > 0); | ||
| assertTrue(average <= elapsed); | ||
| }); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTopLevelBookieReadCounters() throws Exception { | ||
| long startNanos = MathUtils.nowInNano(); | ||
| lh.addEntry("test".getBytes()); | ||
| lh.readEntries(0, 0); | ||
| long elapsed = MathUtils.elapsedNanos(startNanos); | ||
| TestStatsProvider stats = getStatsProvider(0); | ||
| validateOpStat(stats, new String[]{ | ||
| SERVER_SCOPE + ".READ_ENTRY", | ||
| SERVER_SCOPE + ".READ_ENTRY_REQUEST", | ||
| SERVER_SCOPE + ".BookieReadThreadPool.task_queued", | ||
| SERVER_SCOPE + ".BookieReadThreadPool.task_execution", | ||
| }, (count, average) -> { | ||
| assertTrue(count == 1); | ||
| assertTrue(average > 0); | ||
| assertTrue(average <= elapsed); | ||
| }); | ||
| validateOpStat(stats, new String[]{ | ||
| SERVER_SCOPE + ".CHANNEL_WRITE" | ||
| }, (count, average) -> { | ||
| assertTrue(count > 0); | ||
| assertTrue(average > 0); | ||
| assertTrue(average <= elapsed); | ||
| }); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line seems to related to the issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for typo, it does not seem to be related to the issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stopAutoRecoveryService gets called as part of of killBookie. I refactored it a little to make the bs/bsLoggers state maintenance slightly less error prone.