Comparison of concurrent queue concurrent1_queue and blocked queue blockingqueue in queue high concurrency Performance

Source: Internet
Author: User

The test results show that the performance of blocking and concurrent queues is not much different in the case of high concurrency.

 

 

1 test. Java code reference http://blog.csdn.net/arkblue/archive/2011/01/14/6138598.aspx

 

 

View plain
  1. Public class concurrentqueuetest {
  2. Private Static int COUNT = 100000;
  3. Private Static int thread_num = 10;
  4. Private Static javasicbarrierthread = new javasicbarrierthread ();
  5. Private Static concurrent1_queue conqueue = new concurrent1_queue ();
  6. Private Static jsonblockingqueue linkqueue = new jsonblockingqueue ();
  7. Static class concurrentlinkedqueueproducer extends test {
  8. Public concurrentlinkedqueueproducer (string ID, cyclicbarrier barrier,
  9. Long Count, int threadnum, executorservice executor ){
  10. Super (ID, barrier, Count, threadnum, executor );
  11. }
  12. @ Override
  13. Protected void test (){
  14. Conqueue. Add (1 );
  15. }
  16. }
  17. Static class extends blockingqueueproducer extends test {
  18. Public writable blockingqueueproducer (string ID, cyclicbarrier barrier,
  19. Long Count, int threadnum, executorservice executor ){
  20. Super (ID, barrier, Count, threadnum, executor );
  21. }
  22. @ Override
  23. Protected void test (){
  24. Conqueue. Add (1 );
  25. }
  26. }
  27. Static class extends icbarrierthread extends thread {
  28. @ Override
  29. Public void run (){
  30. Conqueue. Clear ();
  31. Linkqueue. Clear ();
  32. }
  33. }
  34. Public static void test (string ID, Long Count, int threadnum,
  35. Executorservice executor ){
  36. Final required icbarrier barrier = new required icbarrier (threadnum + 1,
  37. Cyclicbarrierthread );
  38. System. Out. println ("========================== ");
  39. System. Out. println ("Count =" + Count + "/t" + "Thread Count ="
  40. + Threadnum );
  41. Concurrenttotaltime + = new concurrentlinkedqueueproducer (
  42. "Concurrentlinkedqueueproducer", barrier, Count, threadnum,
  43. Executor). starttest ();
  44. Linkedblockingtotaltime + = new linkedblockingqueueproducer (
  45. "Linkedblockingqueueproducer", barrier, Count, threadnum,
  46. Executor). starttest ();
  47. Totalthreadcount + = threadnum;
  48. Executor. shutdownnow ();
  49. System. Out. println ("========================== ");
  50. }
  51. Static long concurrenttotaltime = 0;
  52. Static long wait blockingtotaltime = 0;
  53. Static long totalthreadcount = 0;
  54. Public static void main (string [] ARGs) throws interruptedexception {
  55. For (INT I = 1; I <20; I ++ ){
  56. Executorservice executor = executors. newfixedthreadpool (thread_num
  57. * I );
  58. Test ("", Count, 10 * I, executor );
  59. }
  60. System. Out. println ("concurrent1_queue AVG time ="
  61. + Concurrenttotaltime/totalthreadcount );
  62. System. Out. println ("blocked blockingqueue AVG time ="
  63. + Define blockingtotaltime/totalthreadcount );
  64. }
  65. }

 

As a result, it takes 49 milliseconds to run 100,000 concurrent queue operations and 53 milliseconds to block the queue, which is 4 milliseconds faster than the blocking queue on average. The average value algorithm may be inaccurate because the overhead for switching between threads increases as the number of threads increases.

View plain
  1. ====================================
  2. Count = 100000 thread count = 10
  3. Concurrent1_queueproducer = 422
  4. Export blockingqueueproducer = 390
  5. ====================================
  6. ====================================
  7. Count = 100000 thread count = 20
  8. Concurrent1_queueproducer = 782
  9. Export blockingqueueproducer = 828
  10. ====================================
  11. ====================================
  12. Count = 100000 thread count = 30
  13. Concurrent1_queueproducer = 1468
  14. Export blockingqueueproducer = 1422
  15. ====================================
  16. ====================================
  17. Count = 100000 thread count = 40
  18. Concurrent1_queueproducer = 2188
  19. Export blockingqueueproducer = 1297
  20. ====================================
  21. ====================================
  22. Count = 100000 thread count = 50
  23. Concurrent1_queueproducer = 2609
  24. Export blockingqueueproducer = 2625
  25. ====================================
  26. ====================================
  27. Count = 100000 thread count = 60
  28. Concurrent1_queueproducer = 3078
  29. Export blockingqueueproducer = 2969
  30. ====================================
  31. ====================================
  32. Count = 100000 thread count = 70
  33. Concurrent1_queueproducer = 4046
  34. Export blockingqueueproducer = 3594
  35. ====================================
  36. ====================================
  37. Count = 100000 thread count = 80
  38. Concurrent1_queueproducer = 4047
  39. Export blockingqueueproducer = 4078
  40. ====================================
  41. ====================================
  42. Count = 100000 thread count = 90
  43. Concurrent1_queueproducer = 4469
  44. Export blockingqueueproducer = 5109
  45. ====================================
  46. ====================================
  47. Count = 100000 thread count = 100
  48. Concurrent1_queueproducer = 5125
  49. Export blockingqueueproducer = 4922
  50. ====================================
  51. ====================================
  52. Count = 100000 thread count = 110
  53. Concurrent1_queueproducer = 5531
  54. Export blockingqueueproducer = 5969
  55. ====================================
  56. ====================================
  57. Count = 100000 thread count = 120
  58. Concurrent1_queueproducer = 5172
  59. Export blockingqueueproducer = 6188
  60. ====================================
  61. ====================================
  62. Count = 100000 thread count = 130
  63. Concurrent1_queueproducer = 7187
  64. Export blockingqueueproducer = 6594
  65. ====================================
  66. ====================================
  67. Count = 100000 thread count = 140
  68. Concurrent1_queueproducer = 6937
  69. Export blockingqueueproducer = 7782
  70. ====================================
  71. ====================================
  72. Count = 100000 thread count = 150
  73. Concurrent1_queueproducer = 6921
  74. Export blockingqueueproducer = 8875
  75. ====================================
  76. ====================================
  77. Count = 100000 thread count = 160
  78. Concurrent1_queueproducer = 8047
  79. Export blockingqueueproducer = 9250
  80. ====================================
  81. ====================================
  82. Count = 100000 thread count = 170
  83. Concurrent1_queueproducer = 8235
  84. Export blockingqueueproducer = 9656
  85. ====================================
  86. ====================================
  87. Count = 100000 thread count = 180
  88. Concurrent1_queueproducer = 9062
  89. Export blockingqueueproducer = 9719
  90. ====================================
  91. ====================================
  92. Count = 100000 thread count = 190
  93. Concurrent1_queueproducer = 9422
  94. Export blockingqueueproducer = 9609
  95. ====================================
  96. Concurrent1_queue AVG time = 49
  97. Required blockingqueue AVG time = 53

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.