From f5f9413cd4defe6d86555defc677f66b9318f760 Mon Sep 17 00:00:00 2001 From: kuangcp Date: Fri, 7 Jun 2024 19:04:55 +0800 Subject: [PATCH] compare data --- .../queue/use/blocking/ReaderWriterTest.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/concurrency/src/test/java/com/github/kuangcp/queue/use/blocking/ReaderWriterTest.java b/concurrency/src/test/java/com/github/kuangcp/queue/use/blocking/ReaderWriterTest.java index 350fa77..d7b4aa9 100644 --- a/concurrency/src/test/java/com/github/kuangcp/queue/use/blocking/ReaderWriterTest.java +++ b/concurrency/src/test/java/com/github/kuangcp/queue/use/blocking/ReaderWriterTest.java @@ -50,7 +50,8 @@ private CountDownLatch startWriter(QueueChannel> channel) { log.info("start"); List> batch = new ArrayList<>(100); while (channel.isRunning()) { - List task = channel.poll(1, TimeUnit.SECONDS); + // 这里的超时时间按需使用,设置的越长就会接收第一条数据的延迟更高(例如设置1s那单个Writer任务最低会消耗1s时间),但是CPU短时忙轮询(毛刺)的情况好一些 + List task = channel.poll(50, TimeUnit.MILLISECONDS); if (Objects.isNull(task)) { continue; } @@ -77,23 +78,29 @@ private CountDownLatch startWriter(QueueChannel> channel) { @Test public void testTime() throws Exception { - log.info("average={}", avg("677,677,679,680,110,110,127,136,187,147,119,3840,172,1537,1624,185,13492,13035,116,153,2125,6313,17584")); - log.info("average={}", avg("102,102,101,146,107,104,78,132,166,147,164,3948,159,1507,1648,150,11921,11749,113,143,2124,6045,16872")); - log.info("average={}", avg("55,52,52,92,52,51,65,72,438,94,101,5547,101,4108,4176,92,15316,15068,66,99,7270,20601,3570")); - log.info("average={}", avg("52,51,51,97,52,54,64,70,421,94,125,5266,95,4035,4191,95,15743,15638,71,119,7084,20568,3496")); - - - // 包含线程启动成本 - log.info("NONE ={}", avg("283,289,265,306,54,53,67,73,455,97,5864,5416,104,102,130,129,117,110,98,1839,6493,7127,8612,14486,98,115,3485,3399,14345,14287,67,97,92,3642,6931,21040")); + System.out.println("Start poll 50ms"); + // poll 50ms + log.info("QUEUE={}", avg("677,677,679,680,110,110,127,136,187,147,119,3840,172,1537,1624,185,13492,13035,116,153,2125,6313,17584")); // 包含线程启动成本 + log.info("QUEUE={}", avg("102,102,101,146,107,104,78,132,166,147,164,3948,159,1507,1648,150,11921,11749,113,143,2124,6045,16872")); + log.info("NONE ={}", avg("55,52,52,92,52,51,65,72,438,94,101,5547,101,4108,4176,92,15316,15068,66,99,7270,20601,3570")); + log.info("NONE ={}", avg("52,51,51,97,52,54,64,70,421,94,125,5266,95,4035,4191,95,15743,15638,71,119,7084,20568,3496")); + + System.out.println("Start poll 50ms"); + log.info("NONE ={}", avg("283,289,265,306,54,53,67,73,455,97,5864,5416,104,102,130,129,117,110,98,1839,6493,7127,8612,14486,98,115,3485,3399,14345,14287,67,97,92,3642,6931,21040")); // 包含线程启动成本 log.info("QUEUE={}", avg("106,106,103,149,102,103,63,117,145,143,4009,4323,152,155,149,150,150,150,211,481,5613,5891,7703,13397,161,182,1307,1309,11543,11501,123,199,204,2147,6122,18479")); - log.info("NONE ={}", avg("54,55,57,120,54,52,82,76,409,89,5228,5004,99,103,107,111,94,95,102,2004,6804,7099,9211,15073,119,129,3180,3417,14186,14148,106,96,96,3638,7399,20458")); log.info("QUEUE={}", avg("101,101,101,145,101,101,164,131,149,143,3870,3922,170,171,175,171,145,144,177,424,4703,4681,7090,12207,156,175,1301,1328,12619,12382,145,198,200,2145,6203,18045")); - // writer方不用缓冲队列,读一条就写一条 但是出bug了,缺数据,应该是数据没flush到,但是没flush接口暴露 - // 包含线程启动成本 - log.info("QUEUE={}", avg("272,272,272,272,67,63,59,52,137,67,4335,4494,65,67,64,65,63,64,64,418,4937,4861,6861,12732,71,65,1300,1372,12305,12654,52,66,86,2357,6872,18460")); + System.out.println("Start poll 50ms"); + // writer时不用缓冲队列,读一条就写一条 但是Excel缺数据了,应该是数据没flush到,但是EasyExcel没flush接口暴露 csv才有 + log.info("QUEUE={}", avg("272,272,272,272,67,63,59,52,137,67,4335,4494,65,67,64,65,63,64,64,418,4937,4861,6861,12732,71,65,1300,1372,12305,12654,52,66,86,2357,6872,18460")); // 包含线程启动成本 log.info("QUEUE={}", avg("52,50,51,66,50,52,52,55,119,63,4613,4914,65,67,66,67,63,65,65,387,5175,5236,7604,12996,65,65,1199,1304,12848,12969,69,66,74,2060,6450,18039")); + + System.out.println("Start poll 20ms"); + log.info("QUEUE={}", avg("280,318,319,360,74,73,100,94,163,140,4205,4357,116,114,133,134,125,115,135,528,5209,5213,7350,13044,146,167,1237,1317,12525,12616,84,138,136,1961,6017,17213")); // 包含线程启动成本 + log.info("QUEUE={}", avg("78,78,79,113,72,72,52,105,216,127,4121,4297,118,121,138,138,119,118,156,491,4674,4943,7396,12626,114,140,1367,1621,12460,13197,84,121,126,2081,5878,17368")); + log.info("QUEUE={}", avg("72,72,72,115,74,71,86,88,159,110,3874,3899,114,124,116,117,113,115,138,503,4964,5029,7201,12581,118,144,1435,1483,12354,12123,92,117,112,1992,5825,16973")); + } private static IntSummaryStatistics avg(String x) {