Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JRuby评测中,花在线程初始化和线程连接上的大量时间意味着什么?_Ruby_Multithreading_Profiling_Jruby - Fatal编程技术网

在JRuby评测中,花在线程初始化和线程连接上的大量时间意味着什么?

在JRuby评测中,花在线程初始化和线程连接上的大量时间意味着什么?,ruby,multithreading,profiling,jruby,Ruby,Multithreading,Profiling,Jruby,我正在尝试使用JRuby的内置分析器评测应用程序 大部分时间都花在感兴趣的类中。方法\u是感兴趣的,它的大部分时间依次花在线程#初始化和线程#连接 total self children calls method ---------------------------------------------------------------- 31.36 0.02 31.35 4525 Array#ea

我正在尝试使用JRuby的内置分析器评测应用程序

大部分时间都花在感兴趣的
类中。方法\u是感兴趣的
,它的大部分时间依次花在
线程#初始化
线程#连接

     total        self    children       calls  method
----------------------------------------------------------------
     31.36        0.02       31.35        4525  Array#each
     31.06        0.00       31.06           2  Test::Unit::RunCount.run_once
     31.06        0.00       31.06           1  Test::Unit::RunCount.run
     31.06        0.00       31.06           1  MiniTest::Unit#run
     31.06        0.00       31.05           1  MiniTest::Unit#_run
     31.01        0.00       31.01        2219  Kernel.send
     31.00        0.00       31.00           1  MiniTest::Unit#run_tests
     31.00        0.00       31.00           1  MiniTest::Unit#_run_anything
     30.99        0.00       30.99           1  Test::Unit::Runner#_run_suites
     30.99        0.00       30.99           5  MiniTest::Unit#_run_suite
     30.99        0.00       30.98       21629  Array#map
     30.98        0.00       30.98           1  Test::Unit::TestCase#run
     30.98        0.00       30.98           1  MiniTest::Unit::TestCase#run
     30.98        0.00       30.98         659  BasicObject#__send__
     30.98        0.00       30.98           1  MyTestClass#my_test_method
     30.80        0.00       30.80          18  Enumerable.each_with_index
     30.77        0.00       30.77          15  MyTestHelper.generate_call_parser_based_on_barcoded_sequence
     30.26        0.00       30.25        4943  Class#new_proxy
     26.13        0.00       26.13          15  MyProductionClass1#my_production_method1

<snip boring methods with zero self time>

     24.27        0.00       24.27          15  ClassIsOfInterest.method_that_is_of_interest
     13.71        0.01       13.71         541  Enumerable.map
     13.48        0.86       12.63          30  Range#each
     12.62        0.22       12.41         450  Thread.new
     12.41       12.41        0.00         450  Thread#initialize
     10.78       10.78        0.00         450  Thread#join
      4.03        0.12        3.91         539  Kernel.require
      3.34        0.00        3.34         248  Kernel.require
      2.49        0.00        2.49          15  MyTestFixture.create_fixture

<snip boring methods with small total times>

Thread#initialize
(在第一个配置文件中)和
Thread#join
的大时间值是否表示负责线程的代码需要一段时间,或者仅仅是线程内执行的代码需要一段时间?

您看到
thread\join
的原因是主线程花费大量时间等待其他线程完成。花在感兴趣的
方法上的大部分时间都花在阻塞
线程#连接上
,因为它没有做任何其他工作。我不会太担心这个问题——概要文件只是说您的一个线程阻塞了其他线程正在做的事情。在这种情况下,更好的性能度量是总运行时间,使用不同数量的线程运行代码,并查看最佳点在哪里

出现
Thread.new
/
Thread#initialize
的原因是线程是昂贵的创建对象。如果您经常调用此方法,并且每次都会创建所有这些线程,我建议您查看Java的API。使用
执行器创建一个线程池
一次(当应用程序启动时),并将所有任务提交到线程池,而不是创建新线程(您可以使用等待所有任务完成,或者在提交任务时获得的
FutureTask
实例上调用
#get

 23.16        0.00       23.15          15  ClassIsOfInterest.method_that_is_of_interest
 22.73       22.73        0.00          45  Thread#join
  4.18        0.08        4.10         539  Kernel.require
  3.56        0.00        3.56         248  Kernel.require
  2.78        0.00        2.78          15  MyTestFixture.create_fixture