宝马执行速度非常慢

时间:2016-05-11 08:45:50

标签: ruby rubygems

我有一个使用thor构建的自定义CLI gem(&#39; pm&#39;),它在开发系统上以可接受的时间运行,但在生产系统上速度非常慢,我不明白为什么。< / p>

规格,时间和结果两个系统的分析都是:

development system          production system
------------------          -----------------
real    0m6.859s            real    0m53.405s
user    0m6.464s            user    0m52.334s
sys     0m0.364s            sys     0m0.840s

prod system: Linux grumples 3.13.0-37-generic #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

dev system: Linux cb-8 4.2.0-36-generic #41-Ubuntu SMP Mon Apr 18 15:49:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

MRI ruby 2.2.2

Profiling produces:

dev system

   %   cumulative   self              self     total
 time   seconds   seconds    calls  ms/call  ms/call  name
  9.82     0.55      0.55     1481     0.37    15.83  Kernel#require
  4.46     0.80      0.25     5376     0.05     0.12  Erubis::TinyEruby#convert
  4.11     1.03      0.23     8682     0.03     0.07  Neo4j::Shared::TypecastedAttributes#_attribute_typecaster
  3.39     1.22      0.19     7831     0.02     0.02  Regexp#match
  3.39     1.41      0.19    20519     0.01     0.03  Domainatrix::DomainParser#read_dat_file
  3.04     1.58      0.17    15480     0.01     0.03  MIME::Type.simplify_matchdata
  3.04     1.75      0.17     6386     0.03     0.24  Array#map
  1.96     1.86      0.11     8682     0.01     0.11  Neo4j::Shared::TypecastedAttributes#attribute
  1.96     1.97      0.11    14529     0.01     0.40  Array#each
  1.96     2.08      0.11    78487     0.00     0.00  Hash#[]
  1.79     2.18      0.10     9874     0.01     0.24  Neo4j::Shared::Attributes#attributes_map
  1.79     2.28      0.10      154     0.65     1.30  Hash#each


prodn system

  %   cumulative   self              self     total
 time   seconds   seconds    calls  ms/call  ms/call  name
 40.63     1.93      1.93    90324     0.02     0.08  Gem::Dependency#matching_specs
 15.16     2.65      0.72     5122     0.14     4.15  Array#each
  7.79     3.02      0.37     3252     0.11     0.20  Gem::Version#<=>
  4.21     3.22      0.20    10590     0.02     0.04  Gem::Specification#runtime_dependencies
  3.58     3.39      0.17    87738     0.00     0.00  String#===
  2.53     3.51      0.12    87942     0.00     0.00  Gem::StubSpecification#name
  2.53     3.63      0.12     3966     0.03     0.06  Gem::Version#bump
  2.32     3.74      0.11     4304     0.03     0.03  Kernel#initialize_dup
  1.68     3.82      0.08     1583     0.05     0.54  nil#
  1.47     3.89      0.07     2610     0.03     0.07  Array#any?
  1.26     3.95      0.06     3252     0.02     0.06  Gem::Version#version
  1.05     4.00      0.05    17117     0.00     0.00  Module#===
  1.05     4.05      0.05     2023     0.02     0.08  Gem::BasicSpecification#contains_requirable_file?

Gem::Dependency#matching_specs中有40%的时间似乎已经发生了很多必须可以优化的事情。

我很感激有关如何进一步调查生产版本如此缓慢的原因的任何指导。

此致

附录1

.gemrc文件在prodn和amp;开发系统

~/.gemrc

---
:backtrace: false
:bulk_threshold: 1000
:sources:
- https://rubygems.org
- http://[private gem server]
:update_sources: true
:verbose: true
gem: '--no-document --no-ri'

两个系统上都没有/ etc / gemrc

附录2

来自dev&amp; amp;的宝石env&#;生产系统

生产系统

gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.5
  - RUBY VERSION: 2.2.2 (2015-04-13 patchlevel 95) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/ql/.gem/ruby/2.2.2
  - RUBY EXECUTABLE: /opt/rubies/ruby-2.2.2/bin/ruby
  - EXECUTABLE DIRECTORY: /home/ql/.gem/ruby/2.2.2/bin
  - SPEC CACHE DIRECTORY: /home/ql/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /opt/rubies/ruby-2.2.2/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/ql/.gem/ruby/2.2.2
     - /opt/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - :sources => ["https://rubygems.org", "http://[private gem server]"]
     - "gem" => "--no-document --no-ri"
  - REMOTE SOURCES:
     - https://rubygems.org
     - http://[private gem server]
  - SHELL PATH:
     - /home/ql/.gem/ruby/2.2.2/bin
     - /opt/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0/bin
     - /opt/rubies/ruby-2.2.2/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /usr/games
     - /usr/local/games
     - /usr/lib/jvm/java-8-oracle/bin
     - /usr/lib/jvm/java-8-oracle/db/bin
     - /usr/lib/jvm/java-8-oracle/jre/bin

开发系统

gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.8
  - RUBY VERSION: 2.2.2 (2015-04-13 patchlevel 95) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/cb/.gem/ruby/2.2.2
  - RUBY EXECUTABLE: /home/cb/.rubies/ruby-2.2.2/bin/ruby
  - EXECUTABLE DIRECTORY: /home/cb/.gem/ruby/2.2.2/bin
  - SPEC CACHE DIRECTORY: /home/cb/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /home/cb/.rubies/ruby-2.2.2/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/cb/.gem/ruby/2.2.2
     - /home/cb/.rubies/ruby-2.2.2/lib/ruby/gems/2.2.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - :sources => ["https://rubygems.org", "http://[private gem server]/"]
     - "gem" => "--no-document"
  - REMOTE SOURCES:
     - https://rubygems.org
     - http://[private gem server]/
  - SHELL PATH:
     - /home/cb/.gem/ruby/2.2.2/bin
     - /home/cb/.rubies/ruby-2.2.2/lib/ruby/gems/2.2.0/bin
     - /home/cb/.rubies/ruby-2.2.2/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /usr/games
     - /usr/local/games
     - .
     - bin

附录3 生产服务器的top摘要

top - 20:11:26 up 1 day,  1:18,  1 user,  load average: 0.02, 0.04, 0.05
Tasks:  94 total,   2 running,  92 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.3 us,  0.2 sy,  0.0 ni, 99.3 id,  0.0 wa,  0.0 hi,  0.2 si,  0.0 st
KiB Mem:   4048288 total,  2797220 used,  1251068 free,   369612 buffers
KiB Swap:        0 total,        0 used,        0 free.   922420 cached Mem

生产@ mo的事情并不多。开发系统正在努力工作。系统不会对@ mo进行任何交换处罚。

删除私有gem服务器url上的尾部斜杠对执行时间没有影响。

附录4 在16GB mem DO Droplet上测试了私有宝石并且性能问题消失了。两台服务器都使用相同的Ansible手册构建。

1 个答案:

答案 0 :(得分:0)

通过切换到具有从4Gb到16Gb的增加的内存的另一个vps找到了解决方案(即使在两种情况下都未使用交换空间)。 两个系统都使用相同的Ansible playbook(所有组件的相同版本)构建。 性能问题蒸发了,并不完全确定原因。但那就行了。