|
18 | 18 | package org.apache.hadoop.hbase.regionserver; |
19 | 19 |
|
20 | 20 | import java.io.IOException; |
| 21 | +import java.util.ArrayList; |
21 | 22 | import java.util.Collection; |
22 | 23 | import java.util.List; |
| 24 | +import java.util.Map; |
23 | 25 | import java.util.OptionalDouble; |
24 | 26 | import java.util.OptionalLong; |
| 27 | +import java.util.concurrent.ConcurrentHashMap; |
25 | 28 | import java.util.concurrent.ScheduledExecutorService; |
26 | 29 | import java.util.concurrent.TimeUnit; |
27 | 30 |
|
@@ -113,6 +116,8 @@ class MetricsRegionServerWrapperImpl |
113 | 116 | private volatile long mobFileCacheCount = 0; |
114 | 117 | private volatile long blockedRequestsCount = 0L; |
115 | 118 | private volatile long averageRegionSize = 0L; |
| 119 | + protected final Map<String, ArrayList<Long>> |
| 120 | + requestsCountCache = new ConcurrentHashMap<String, ArrayList<Long>>(); |
116 | 121 |
|
117 | 122 | private ScheduledExecutorService executor; |
118 | 123 | private Runnable runnable; |
@@ -652,9 +657,6 @@ public double getMobFileCacheHitPercent() { |
652 | 657 | public class RegionServerMetricsWrapperRunnable implements Runnable { |
653 | 658 |
|
654 | 659 | private long lastRan = 0; |
655 | | - private long lastRequestCount = 0; |
656 | | - private long lastReadRequestsCount = 0; |
657 | | - private long lastWriteRequestsCount = 0; |
658 | 660 |
|
659 | 661 | @Override |
660 | 662 | synchronized public void run() { |
@@ -696,7 +698,40 @@ synchronized public void run() { |
696 | 698 | long tempMobScanCellsSize = 0; |
697 | 699 | long tempBlockedRequestsCount = 0; |
698 | 700 | int regionCount = 0; |
| 701 | + |
| 702 | + long currentReadRequestsCount = 0; |
| 703 | + long currentWriteRequestsCount = 0; |
| 704 | + long lastReadRequestsCount = 0; |
| 705 | + long lastWriteRequestsCount = 0; |
| 706 | + long readRequestsDelta = 0; |
| 707 | + long writeRequestsDelta = 0; |
| 708 | + long totalReadRequestsDelta = 0; |
| 709 | + long totalWriteRequestsDelta = 0; |
| 710 | + String encodedRegionName; |
699 | 711 | for (HRegion r : regionServer.getOnlineRegionsLocalContext()) { |
| 712 | + encodedRegionName = r.getRegionInfo().getEncodedName(); |
| 713 | + currentReadRequestsCount = r.getReadRequestsCount(); |
| 714 | + currentWriteRequestsCount = r.getWriteRequestsCount(); |
| 715 | + if (requestsCountCache.containsKey(encodedRegionName)) { |
| 716 | + lastReadRequestsCount = requestsCountCache.get(encodedRegionName).get(0); |
| 717 | + lastWriteRequestsCount = requestsCountCache.get(encodedRegionName).get(1); |
| 718 | + readRequestsDelta = currentReadRequestsCount - lastReadRequestsCount; |
| 719 | + writeRequestsDelta = currentWriteRequestsCount - lastWriteRequestsCount; |
| 720 | + totalReadRequestsDelta += readRequestsDelta; |
| 721 | + totalWriteRequestsDelta += writeRequestsDelta; |
| 722 | + //Update cache for our next comparision |
| 723 | + requestsCountCache.get(encodedRegionName).set(0,currentReadRequestsCount); |
| 724 | + requestsCountCache.get(encodedRegionName).set(1,currentWriteRequestsCount); |
| 725 | + } else { |
| 726 | + // List[0] -> readRequestCount |
| 727 | + // List[1] -> writeRequestCount |
| 728 | + ArrayList<Long> requests = new ArrayList<Long>(2); |
| 729 | + requests.add(currentReadRequestsCount); |
| 730 | + requests.add(currentWriteRequestsCount); |
| 731 | + requestsCountCache.put(encodedRegionName, requests); |
| 732 | + totalReadRequestsDelta += currentReadRequestsCount; |
| 733 | + totalWriteRequestsDelta += currentWriteRequestsCount; |
| 734 | + } |
700 | 735 | tempNumMutationsWithoutWAL += r.getNumMutationsWithoutWAL(); |
701 | 736 | tempDataInMemoryWithoutWAL += r.getDataInMemoryWithoutWAL(); |
702 | 737 | tempReadRequestsCount += r.getReadRequestsCount(); |
@@ -783,25 +818,14 @@ synchronized public void run() { |
783 | 818 | } |
784 | 819 | // If we've time traveled keep the last requests per second. |
785 | 820 | if ((currentTime - lastRan) > 0) { |
786 | | - long currentRequestCount = getTotalRowActionRequestCount(); |
787 | | - requestsPerSecond = (currentRequestCount - lastRequestCount) / |
| 821 | + requestsPerSecond = (totalReadRequestsDelta + totalWriteRequestsDelta) / |
788 | 822 | ((currentTime - lastRan) / 1000.0); |
789 | | - lastRequestCount = currentRequestCount; |
790 | | - |
791 | | - long intervalReadRequestsCount = tempReadRequestsCount - lastReadRequestsCount; |
792 | | - long intervalWriteRequestsCount = tempWriteRequestsCount - lastWriteRequestsCount; |
793 | 823 |
|
794 | | - double readRequestsRatePerMilliSecond = ((double)intervalReadRequestsCount/ |
795 | | - (double)period); |
796 | | - double writeRequestsRatePerMilliSecond = ((double)intervalWriteRequestsCount/ |
797 | | - (double)period); |
| 824 | + double readRequestsRatePerMilliSecond = (double)totalReadRequestsDelta / period; |
| 825 | + double writeRequestsRatePerMilliSecond = (double)totalWriteRequestsDelta / period; |
798 | 826 |
|
799 | 827 | readRequestsRatePerSecond = readRequestsRatePerMilliSecond * 1000.0; |
800 | 828 | writeRequestsRatePerSecond = writeRequestsRatePerMilliSecond * 1000.0; |
801 | | - |
802 | | - lastReadRequestsCount = tempReadRequestsCount; |
803 | | - lastWriteRequestsCount = tempWriteRequestsCount; |
804 | | - |
805 | 829 | } |
806 | 830 | lastRan = currentTime; |
807 | 831 |
|
|
0 commit comments