• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / rocketmq / 7926

pending completion
7926

push

travis-ci-com

GitHub
[ISSUE #5965] Fix lmqTopicQueueTable initialization (#5967)

10 of 10 new or added lines in 2 files covered. (100.0%)

22455 of 43079 relevant lines covered (52.13%)

1.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

42.3
/store/src/main/java/org/apache/rocketmq/store/StoreStatsService.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
package org.apache.rocketmq.store;
18

19
import java.text.MessageFormat;
20
import java.util.ArrayList;
21
import java.util.HashMap;
22
import java.util.LinkedList;
23
import java.util.List;
24
import java.util.Map;
25
import java.util.TreeMap;
26
import java.util.concurrent.ConcurrentHashMap;
27
import java.util.concurrent.ConcurrentMap;
28
import java.util.concurrent.atomic.AtomicLong;
29
import java.util.concurrent.atomic.LongAdder;
30
import java.util.concurrent.locks.ReentrantLock;
31
import org.apache.rocketmq.common.ServiceThread;
32
import org.apache.rocketmq.common.constant.LoggerName;
33
import org.apache.rocketmq.logging.InternalLogger;
34
import org.apache.rocketmq.logging.InternalLoggerFactory;
35

36
public class StoreStatsService extends ServiceThread {
37
    private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME);
2✔
38

39
    private static final int FREQUENCY_OF_SAMPLING = 1000;
40

41
    private static final int MAX_RECORDS_OF_SAMPLING = 60 * 10;
42
    private static final String[] PUT_MESSAGE_ENTIRE_TIME_MAX_DESC = new String[] {
2✔
43
        "[<=0ms]", "[0~10ms]", "[10~50ms]", "[50~100ms]", "[100~200ms]", "[200~500ms]", "[500ms~1s]", "[1~2s]", "[2~3s]", "[3~4s]", "[4~5s]", "[5~10s]", "[10s~]",
44
    };
45

46
    //The rule to define buckets
47
    private static final Map<Integer/*interval step size*/, Integer/*times*/> PUT_MESSAGE_ENTIRE_TIME_BUCKETS = new TreeMap<>();
2✔
48
    //buckets
49
    private TreeMap<Long/*bucket*/, LongAdder/*times*/> buckets = new TreeMap<>();
2✔
50
    private Map<Long/*bucket*/, LongAdder/*times*/> lastBuckets = new TreeMap<>();
2✔
51

52
    private static int printTPSInterval = 60 * 1;
2✔
53

54
    private final LongAdder putMessageFailedTimes = new LongAdder();
2✔
55

56
    private final ConcurrentMap<String, LongAdder> putMessageTopicTimesTotal =
2✔
57
        new ConcurrentHashMap<>(128);
58
    private final ConcurrentMap<String, LongAdder> putMessageTopicSizeTotal =
2✔
59
        new ConcurrentHashMap<>(128);
60

61
    private final LongAdder getMessageTimesTotalFound = new LongAdder();
2✔
62
    private final LongAdder getMessageTransferedMsgCount = new LongAdder();
2✔
63
    private final LongAdder getMessageTimesTotalMiss = new LongAdder();
2✔
64
    private final LinkedList<CallSnapshot> putTimesList = new LinkedList<CallSnapshot>();
2✔
65

66
    private final LinkedList<CallSnapshot> getTimesFoundList = new LinkedList<CallSnapshot>();
2✔
67
    private final LinkedList<CallSnapshot> getTimesMissList = new LinkedList<CallSnapshot>();
2✔
68
    private final LinkedList<CallSnapshot> transferedMsgCountList = new LinkedList<CallSnapshot>();
2✔
69
    private volatile LongAdder[] putMessageDistributeTime;
70
    private volatile LongAdder[] lastPutMessageDistributeTime;
71
    private long messageStoreBootTimestamp = System.currentTimeMillis();
2✔
72
    private volatile long putMessageEntireTimeMax = 0;
2✔
73
    private volatile long getMessageEntireTimeMax = 0;
2✔
74
    // for putMessageEntireTimeMax
75
    private ReentrantLock putLock = new ReentrantLock();
2✔
76
    // for getMessageEntireTimeMax
77
    private ReentrantLock getLock = new ReentrantLock();
2✔
78

79
    private volatile long dispatchMaxBuffer = 0;
2✔
80

81
    private ReentrantLock samplingLock = new ReentrantLock();
2✔
82
    private long lastPrintTimestamp = System.currentTimeMillis();
2✔
83

84
    public StoreStatsService() {
2✔
85
        PUT_MESSAGE_ENTIRE_TIME_BUCKETS.put(1,20);  //0-20
2✔
86
        PUT_MESSAGE_ENTIRE_TIME_BUCKETS.put(2,15);  //20-50
2✔
87
        PUT_MESSAGE_ENTIRE_TIME_BUCKETS.put(5,10);  //50-100
2✔
88
        PUT_MESSAGE_ENTIRE_TIME_BUCKETS.put(10,10);  //100-200
2✔
89
        PUT_MESSAGE_ENTIRE_TIME_BUCKETS.put(50,6);  //200-500
2✔
90
        PUT_MESSAGE_ENTIRE_TIME_BUCKETS.put(100,5);  //500-1000
2✔
91
        PUT_MESSAGE_ENTIRE_TIME_BUCKETS.put(1000,9);  //1s-10s
2✔
92

93
        this.resetPutMessageTimeBuckets();
2✔
94
        this.resetPutMessageDistributeTime();
2✔
95
    }
2✔
96

97
    private void resetPutMessageTimeBuckets() {
98
        TreeMap<Long, LongAdder> nextBuckets = new TreeMap<>();
2✔
99
        AtomicLong index = new AtomicLong(0);
2✔
100
        PUT_MESSAGE_ENTIRE_TIME_BUCKETS.forEach((interval, times) -> {
2✔
101
            for (int i = 0; i < times; i++) {
2✔
102
                nextBuckets.put(index.addAndGet(interval), new LongAdder());
2✔
103
            }
104
        });
2✔
105
        nextBuckets.put(Long.MAX_VALUE, new LongAdder());
2✔
106

107
        this.lastBuckets = this.buckets;
2✔
108
        this.buckets = nextBuckets;
2✔
109
    }
2✔
110

111
    public void incPutMessageEntireTime(long value) {
112
        Map.Entry<Long, LongAdder> targetBucket = buckets.ceilingEntry(value);
2✔
113
        if (targetBucket != null) {
2✔
114
            targetBucket.getValue().add(1);
2✔
115
        }
116
    }
2✔
117

118
    public double findPutMessageEntireTimePX(double px) {
119
        Map<Long, LongAdder> lastBuckets = this.lastBuckets;
2✔
120
        long start = System.currentTimeMillis();
2✔
121
        double result = 0.0;
2✔
122
        long totalRequest = lastBuckets.values().stream().mapToLong(LongAdder::longValue).sum();
2✔
123
        long pxIndex = (long) (totalRequest * px);
2✔
124
        long passCount = 0;
2✔
125
        List<Long> bucketValue = new ArrayList<>(lastBuckets.keySet());
2✔
126
        for (int i = 0; i < bucketValue.size(); i++) {
2✔
127
            long count = lastBuckets.get(bucketValue.get(i)).longValue();
2✔
128
            if (pxIndex <= passCount + count) {
2✔
129
                long relativeIndex = pxIndex - passCount;
2✔
130
                if (i == 0) {
2✔
131
                    result = count == 0 ? 0 : bucketValue.get(i) * relativeIndex / (double)count;
×
132
                } else {
133
                    long lastBucket = bucketValue.get(i - 1);
2✔
134
                    result = lastBucket + (count == 0 ? 0 : (bucketValue.get(i) - lastBucket) * relativeIndex / (double)count);
2✔
135
                }
136
                break;
2✔
137
            } else {
138
                passCount += count;
2✔
139
            }
140
        }
141
        log.info("findPutMessageEntireTimePX {}={}ms cost {}ms", px, String.format("%.2f", result), System.currentTimeMillis() - start);
2✔
142
        return result;
2✔
143
    }
144

145
    private LongAdder[] resetPutMessageDistributeTime() {
146
        LongAdder[] next = new LongAdder[13];
2✔
147
        for (int i = 0; i < next.length; i++) {
2✔
148
            next[i] = new LongAdder();
2✔
149
        }
150

151
        this.lastPutMessageDistributeTime = this.putMessageDistributeTime;
2✔
152

153
        this.putMessageDistributeTime = next;
2✔
154

155
        return lastPutMessageDistributeTime;
2✔
156
    }
157

158
    public long getPutMessageEntireTimeMax() {
159
        return putMessageEntireTimeMax;
×
160
    }
161

162
    public void setPutMessageEntireTimeMax(long value) {
163
        this.incPutMessageEntireTime(value);
2✔
164
        final LongAdder[] times = this.putMessageDistributeTime;
2✔
165

166
        if (null == times)
2✔
167
            return;
×
168

169
        // us
170
        if (value <= 0) {
2✔
171
            times[0].add(1);
2✔
172
        } else if (value < 10) {
2✔
173
            times[1].add(1);
2✔
174
        } else if (value < 50) {
2✔
175
            times[2].add(1);
2✔
176
        } else if (value < 100) {
2✔
177
            times[3].add(1);
1✔
178
        } else if (value < 200) {
2✔
179
            times[4].add(1);
×
180
        } else if (value < 500) {
2✔
181
            times[5].add(1);
×
182
        } else if (value < 1000) {
2✔
183
            times[6].add(1);
×
184
        }
185
        // 2s
186
        else if (value < 2000) {
2✔
187
            times[7].add(1);
×
188
        }
189
        // 3s
190
        else if (value < 3000) {
2✔
191
            times[8].add(1);
2✔
192
        }
193
        // 4s
194
        else if (value < 4000) {
×
195
            times[9].add(1);
×
196
        }
197
        // 5s
198
        else if (value < 5000) {
×
199
            times[10].add(1);
×
200
        }
201
        // 10s
202
        else if (value < 10000) {
×
203
            times[11].add(1);
×
204
        } else {
205
            times[12].add(1);
×
206
        }
207

208
        if (value > this.putMessageEntireTimeMax) {
2✔
209
            this.putLock.lock();
2✔
210
            this.putMessageEntireTimeMax =
2✔
211
                value > this.putMessageEntireTimeMax ? value : this.putMessageEntireTimeMax;
212
            this.putLock.unlock();
2✔
213
        }
214
    }
2✔
215

216
    public long getGetMessageEntireTimeMax() {
217
        return getMessageEntireTimeMax;
×
218
    }
219

220
    public void setGetMessageEntireTimeMax(long value) {
221
        if (value > this.getMessageEntireTimeMax) {
2✔
222
            this.getLock.lock();
2✔
223
            this.getMessageEntireTimeMax =
2✔
224
                value > this.getMessageEntireTimeMax ? value : this.getMessageEntireTimeMax;
225
            this.getLock.unlock();
2✔
226
        }
227
    }
2✔
228

229
    public long getDispatchMaxBuffer() {
230
        return dispatchMaxBuffer;
×
231
    }
232

233
    public void setDispatchMaxBuffer(long value) {
234
        this.dispatchMaxBuffer = value > this.dispatchMaxBuffer ? value : this.dispatchMaxBuffer;
×
235
    }
×
236

237
    @Override
238
    public String toString() {
239
        final StringBuilder sb = new StringBuilder(1024);
×
240
        Long totalTimes = getPutMessageTimesTotal();
×
241
        if (0 == totalTimes) {
×
242
            totalTimes = 1L;
×
243
        }
244

245
        sb.append("\truntime: " + this.getFormatRuntime() + "\r\n");
×
246
        sb.append("\tputMessageEntireTimeMax: " + this.putMessageEntireTimeMax + "\r\n");
×
247
        sb.append("\tputMessageTimesTotal: " + totalTimes + "\r\n");
×
248
        sb.append("\tgetPutMessageFailedTimes: " + this.getPutMessageFailedTimes() + "\r\n");
×
249
        sb.append("\tputMessageSizeTotal: " + this.getPutMessageSizeTotal() + "\r\n");
×
250
        sb.append("\tputMessageDistributeTime: " + this.getPutMessageDistributeTimeStringInfo(totalTimes)
×
251
            + "\r\n");
252
        sb.append("\tputMessageAverageSize: " + (this.getPutMessageSizeTotal() / totalTimes.doubleValue())
×
253
            + "\r\n");
254
        sb.append("\tdispatchMaxBuffer: " + this.dispatchMaxBuffer + "\r\n");
×
255
        sb.append("\tgetMessageEntireTimeMax: " + this.getMessageEntireTimeMax + "\r\n");
×
256
        sb.append("\tputTps: " + this.getPutTps() + "\r\n");
×
257
        sb.append("\tgetFoundTps: " + this.getGetFoundTps() + "\r\n");
×
258
        sb.append("\tgetMissTps: " + this.getGetMissTps() + "\r\n");
×
259
        sb.append("\tgetTotalTps: " + this.getGetTotalTps() + "\r\n");
×
260
        sb.append("\tgetTransferedTps: " + this.getGetTransferedTps() + "\r\n");
×
261
        return sb.toString();
×
262
    }
263

264
    public long getPutMessageTimesTotal() {
265
        Map<String, LongAdder> map = putMessageTopicTimesTotal;
2✔
266
        return map.values()
2✔
267
                .parallelStream()
2✔
268
                .mapToLong(LongAdder::longValue)
2✔
269
                .sum();
2✔
270
    }
271

272
    private String getFormatRuntime() {
273
        final long millisecond = 1;
×
274
        final long second = 1000 * millisecond;
×
275
        final long minute = 60 * second;
×
276
        final long hour = 60 * minute;
×
277
        final long day = 24 * hour;
×
278
        final MessageFormat messageFormat = new MessageFormat("[ {0} days, {1} hours, {2} minutes, {3} seconds ]");
×
279

280
        long time = System.currentTimeMillis() - this.messageStoreBootTimestamp;
×
281
        long days = time / day;
×
282
        long hours = (time % day) / hour;
×
283
        long minutes = (time % hour) / minute;
×
284
        long seconds = (time % minute) / second;
×
285
        return messageFormat.format(new Long[] {days, hours, minutes, seconds});
×
286
    }
287

288
    public long getPutMessageSizeTotal() {
289
        Map<String, LongAdder> map = putMessageTopicSizeTotal;
×
290
        return map.values()
×
291
                .parallelStream()
×
292
                .mapToLong(LongAdder::longValue)
×
293
                .sum();
×
294
    }
295

296
    private String getPutMessageDistributeTimeStringInfo(Long total) {
297
        return this.putMessageDistributeTimeToString();
×
298
    }
299

300
    private String getPutTps() {
301
        StringBuilder sb = new StringBuilder();
×
302

303
        sb.append(this.getPutTps(10));
×
304
        sb.append(" ");
×
305

306
        sb.append(this.getPutTps(60));
×
307
        sb.append(" ");
×
308

309
        sb.append(this.getPutTps(600));
×
310

311
        return sb.toString();
×
312
    }
313

314
    private String getGetFoundTps() {
315
        StringBuilder sb = new StringBuilder();
×
316

317
        sb.append(this.getGetFoundTps(10));
×
318
        sb.append(" ");
×
319

320
        sb.append(this.getGetFoundTps(60));
×
321
        sb.append(" ");
×
322

323
        sb.append(this.getGetFoundTps(600));
×
324

325
        return sb.toString();
×
326
    }
327

328
    private String getGetMissTps() {
329
        StringBuilder sb = new StringBuilder();
×
330

331
        sb.append(this.getGetMissTps(10));
×
332
        sb.append(" ");
×
333

334
        sb.append(this.getGetMissTps(60));
×
335
        sb.append(" ");
×
336

337
        sb.append(this.getGetMissTps(600));
×
338

339
        return sb.toString();
×
340
    }
341

342
    private String getGetTotalTps() {
343
        StringBuilder sb = new StringBuilder();
×
344

345
        sb.append(this.getGetTotalTps(10));
×
346
        sb.append(" ");
×
347

348
        sb.append(this.getGetTotalTps(60));
×
349
        sb.append(" ");
×
350

351
        sb.append(this.getGetTotalTps(600));
×
352

353
        return sb.toString();
×
354
    }
355

356
    private String getGetTransferedTps() {
357
        StringBuilder sb = new StringBuilder();
×
358

359
        sb.append(this.getGetTransferedTps(10));
×
360
        sb.append(" ");
×
361

362
        sb.append(this.getGetTransferedTps(60));
×
363
        sb.append(" ");
×
364

365
        sb.append(this.getGetTransferedTps(600));
×
366

367
        return sb.toString();
×
368
    }
369

370
    private String putMessageDistributeTimeToString() {
371
        final LongAdder[] times = this.lastPutMessageDistributeTime;
×
372
        if (null == times)
×
373
            return null;
×
374

375
        final StringBuilder sb = new StringBuilder();
×
376
        for (int i = 0; i < times.length; i++) {
×
377
            long value = times[i].longValue();
×
378
            sb.append(String.format("%s:%d", PUT_MESSAGE_ENTIRE_TIME_MAX_DESC[i], value));
×
379
            sb.append(" ");
×
380
        }
381

382
        return sb.toString();
×
383
    }
384

385
    private String getPutTps(int time) {
386
        String result = "";
×
387
        this.samplingLock.lock();
×
388
        try {
389
            CallSnapshot last = this.putTimesList.getLast();
×
390

391
            if (this.putTimesList.size() > time) {
×
392
                CallSnapshot lastBefore = this.putTimesList.get(this.putTimesList.size() - (time + 1));
×
393
                result += CallSnapshot.getTPS(lastBefore, last);
×
394
            }
395

396
        } finally {
397
            this.samplingLock.unlock();
×
398
        }
399
        return result;
×
400
    }
401

402
    private String getGetFoundTps(int time) {
403
        String result = "";
×
404
        this.samplingLock.lock();
×
405
        try {
406
            CallSnapshot last = this.getTimesFoundList.getLast();
×
407

408
            if (this.getTimesFoundList.size() > time) {
×
409
                CallSnapshot lastBefore =
×
410
                    this.getTimesFoundList.get(this.getTimesFoundList.size() - (time + 1));
×
411
                result += CallSnapshot.getTPS(lastBefore, last);
×
412
            }
413
        } finally {
414
            this.samplingLock.unlock();
×
415
        }
416

417
        return result;
×
418
    }
419

420
    private String getGetMissTps(int time) {
421
        String result = "";
×
422
        this.samplingLock.lock();
×
423
        try {
424
            CallSnapshot last = this.getTimesMissList.getLast();
×
425

426
            if (this.getTimesMissList.size() > time) {
×
427
                CallSnapshot lastBefore =
×
428
                    this.getTimesMissList.get(this.getTimesMissList.size() - (time + 1));
×
429
                result += CallSnapshot.getTPS(lastBefore, last);
×
430
            }
431

432
        } finally {
433
            this.samplingLock.unlock();
×
434
        }
435

436
        return result;
×
437
    }
438

439
    private String getGetTotalTps(int time) {
440
        this.samplingLock.lock();
×
441
        double found = 0;
×
442
        double miss = 0;
×
443
        try {
444
            {
445
                CallSnapshot last = this.getTimesFoundList.getLast();
×
446

447
                if (this.getTimesFoundList.size() > time) {
×
448
                    CallSnapshot lastBefore =
×
449
                        this.getTimesFoundList.get(this.getTimesFoundList.size() - (time + 1));
×
450
                    found = CallSnapshot.getTPS(lastBefore, last);
×
451
                }
452
            }
453
            {
454
                CallSnapshot last = this.getTimesMissList.getLast();
×
455

456
                if (this.getTimesMissList.size() > time) {
×
457
                    CallSnapshot lastBefore =
×
458
                        this.getTimesMissList.get(this.getTimesMissList.size() - (time + 1));
×
459
                    miss = CallSnapshot.getTPS(lastBefore, last);
×
460
                }
461
            }
462

463
        } finally {
464
            this.samplingLock.unlock();
×
465
        }
466

467
        return Double.toString(found + miss);
×
468
    }
469

470
    private String getGetTransferedTps(int time) {
471
        String result = "";
×
472
        this.samplingLock.lock();
×
473
        try {
474
            CallSnapshot last = this.transferedMsgCountList.getLast();
×
475

476
            if (this.transferedMsgCountList.size() > time) {
×
477
                CallSnapshot lastBefore =
×
478
                    this.transferedMsgCountList.get(this.transferedMsgCountList.size() - (time + 1));
×
479
                result += CallSnapshot.getTPS(lastBefore, last);
×
480
            }
481

482
        } finally {
483
            this.samplingLock.unlock();
×
484
        }
485

486
        return result;
×
487
    }
488

489
    public HashMap<String, String> getRuntimeInfo() {
490
        HashMap<String, String> result = new HashMap<String, String>(64);
×
491

492
        Long totalTimes = getPutMessageTimesTotal();
×
493
        if (0 == totalTimes) {
×
494
            totalTimes = 1L;
×
495
        }
496

497
        result.put("bootTimestamp", String.valueOf(this.messageStoreBootTimestamp));
×
498
        result.put("runtime", this.getFormatRuntime());
×
499
        result.put("putMessageEntireTimeMax", String.valueOf(this.putMessageEntireTimeMax));
×
500
        result.put("putMessageTimesTotal", String.valueOf(totalTimes));
×
501
        result.put("putMessageFailedTimes", String.valueOf(this.putMessageFailedTimes));
×
502
        result.put("putMessageSizeTotal", String.valueOf(this.getPutMessageSizeTotal()));
×
503
        result.put("putMessageDistributeTime",
×
504
            String.valueOf(this.getPutMessageDistributeTimeStringInfo(totalTimes)));
×
505
        result.put("putMessageAverageSize",
×
506
            String.valueOf(this.getPutMessageSizeTotal() / totalTimes.doubleValue()));
×
507
        result.put("dispatchMaxBuffer", String.valueOf(this.dispatchMaxBuffer));
×
508
        result.put("getMessageEntireTimeMax", String.valueOf(this.getMessageEntireTimeMax));
×
509
        result.put("putTps", this.getPutTps());
×
510
        result.put("getFoundTps", this.getGetFoundTps());
×
511
        result.put("getMissTps", this.getGetMissTps());
×
512
        result.put("getTotalTps", this.getGetTotalTps());
×
513
        result.put("getTransferedTps", this.getGetTransferedTps());
×
514
        result.put("putLatency99", String.format("%.2f", this.findPutMessageEntireTimePX(0.99)));
×
515
        result.put("putLatency999", String.format("%.2f", this.findPutMessageEntireTimePX(0.999)));
×
516

517
        return result;
×
518
    }
519

520
    public void run() {
521
        log.info(this.getServiceName() + " service started");
2✔
522

523
        while (!this.isStopped()) {
2✔
524
            try {
525
                this.waitForRunning(FREQUENCY_OF_SAMPLING);
2✔
526

527
                this.sampling();
2✔
528

529
                this.printTps();
2✔
530
            } catch (Exception e) {
×
531
                log.warn(this.getServiceName() + " service has exception. ", e);
×
532
            }
2✔
533
        }
534

535
        log.info(this.getServiceName() + " service end");
2✔
536
    }
2✔
537

538
    @Override
539
    public String getServiceName() {
540
        return StoreStatsService.class.getSimpleName();
2✔
541
    }
542

543
    private void sampling() {
544
        this.samplingLock.lock();
2✔
545
        try {
546
            this.putTimesList.add(new CallSnapshot(System.currentTimeMillis(), getPutMessageTimesTotal()));
2✔
547
            if (this.putTimesList.size() > (MAX_RECORDS_OF_SAMPLING + 1)) {
2✔
548
                this.putTimesList.removeFirst();
×
549
            }
550

551
            this.getTimesFoundList.add(new CallSnapshot(System.currentTimeMillis(),
2✔
552
                this.getMessageTimesTotalFound.longValue()));
2✔
553
            if (this.getTimesFoundList.size() > (MAX_RECORDS_OF_SAMPLING + 1)) {
2✔
554
                this.getTimesFoundList.removeFirst();
×
555
            }
556

557
            this.getTimesMissList.add(new CallSnapshot(System.currentTimeMillis(),
2✔
558
                this.getMessageTimesTotalMiss.longValue()));
2✔
559
            if (this.getTimesMissList.size() > (MAX_RECORDS_OF_SAMPLING + 1)) {
2✔
560
                this.getTimesMissList.removeFirst();
×
561
            }
562

563
            this.transferedMsgCountList.add(new CallSnapshot(System.currentTimeMillis(),
2✔
564
                this.getMessageTransferedMsgCount.longValue()));
2✔
565
            if (this.transferedMsgCountList.size() > (MAX_RECORDS_OF_SAMPLING + 1)) {
2✔
566
                this.transferedMsgCountList.removeFirst();
×
567
            }
568

569
        } finally {
570
            this.samplingLock.unlock();
2✔
571
        }
572
    }
2✔
573

574
    private void printTps() {
575
        if (System.currentTimeMillis() > (this.lastPrintTimestamp + printTPSInterval * 1000)) {
2✔
576
            this.lastPrintTimestamp = System.currentTimeMillis();
×
577

578
            log.info("[STORETPS] put_tps {} get_found_tps {} get_miss_tps {} get_transfered_tps {}",
×
579
                this.getPutTps(printTPSInterval),
×
580
                this.getGetFoundTps(printTPSInterval),
×
581
                this.getGetMissTps(printTPSInterval),
×
582
                this.getGetTransferedTps(printTPSInterval)
×
583
            );
584

585
            final LongAdder[] times = this.resetPutMessageDistributeTime();
×
586
            if (null == times)
×
587
                return;
×
588

589
            final StringBuilder sb = new StringBuilder();
×
590
            long totalPut = 0;
×
591
            for (int i = 0; i < times.length; i++) {
×
592
                long value = times[i].longValue();
×
593
                totalPut += value;
×
594
                sb.append(String.format("%s:%d", PUT_MESSAGE_ENTIRE_TIME_MAX_DESC[i], value));
×
595
                sb.append(" ");
×
596
            }
597
            this.resetPutMessageTimeBuckets();
×
598
            this.findPutMessageEntireTimePX(0.99);
×
599
            this.findPutMessageEntireTimePX(0.999);
×
600
            log.info("[PAGECACHERT] TotalPut {}, PutMessageDistributeTime {}", totalPut, sb.toString());
×
601
        }
602
    }
2✔
603

604
    public LongAdder getGetMessageTimesTotalFound() {
605
        return getMessageTimesTotalFound;
2✔
606
    }
607

608
    public LongAdder getGetMessageTimesTotalMiss() {
609
        return getMessageTimesTotalMiss;
2✔
610
    }
611

612
    public LongAdder getGetMessageTransferedMsgCount() {
613
        return getMessageTransferedMsgCount;
2✔
614
    }
615

616
    public LongAdder getPutMessageFailedTimes() {
617
        return putMessageFailedTimes;
2✔
618
    }
619

620
    public LongAdder getSinglePutMessageTopicSizeTotal(String topic) {
621
        LongAdder rs = putMessageTopicSizeTotal.get(topic);
2✔
622
        if (null == rs) {
2✔
623
            rs = new LongAdder();
2✔
624
            LongAdder previous = putMessageTopicSizeTotal.putIfAbsent(topic, rs);
2✔
625
            if (previous != null) {
2✔
626
                rs = previous;
2✔
627
            }
628
        }
629
        return rs;
2✔
630
    }
631

632
    public LongAdder getSinglePutMessageTopicTimesTotal(String topic) {
633
        LongAdder rs = putMessageTopicTimesTotal.get(topic);
2✔
634
        if (null == rs) {
2✔
635
            rs = new LongAdder();
2✔
636
            LongAdder previous = putMessageTopicTimesTotal.putIfAbsent(topic, rs);
2✔
637
            if (previous != null) {
2✔
638
                rs = previous;
×
639
            }
640
        }
641
        return rs;
2✔
642
    }
643

644
    public Map<String, LongAdder> getPutMessageTopicTimesTotal() {
645
        return putMessageTopicTimesTotal;
×
646
    }
647

648
    public Map<String, LongAdder> getPutMessageTopicSizeTotal() {
649
        return putMessageTopicSizeTotal;
×
650
    }
651

652
    static class CallSnapshot {
653
        public final long timestamp;
654
        public final long callTimesTotal;
655

656
        public CallSnapshot(long timestamp, long callTimesTotal) {
2✔
657
            this.timestamp = timestamp;
2✔
658
            this.callTimesTotal = callTimesTotal;
2✔
659
        }
2✔
660

661
        public static double getTPS(final CallSnapshot begin, final CallSnapshot end) {
662
            long total = end.callTimesTotal - begin.callTimesTotal;
×
663
            Long time = end.timestamp - begin.timestamp;
×
664

665
            double tps = total / time.doubleValue();
×
666

667
            return tps * 1000;
×
668
        }
669
    }
670
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc