Sha256: 0d73a998394262a323bb8d205c1def8d79b7f2ee2d025dd378f8dafefa8da940

Contents?: true

Size: 1.07 KB

Versions: 15

Compression:

Stored size: 1.07 KB

Contents

require_relative "../lib/pitchfork/mem_info"

module App
  CONST_NUM = Integer(ENV.fetch("NUM", 100_000))

  CONST_NUM.times do |i|
    class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
      Const#{i} = Module.new

      def self.lookup_#{i}
        Const#{i}
      end
    RUBY
  end

  class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
    def self.warmup
      #{CONST_NUM.times.map { |i| "lookup_#{i}"}.join("\n")}
    end
  RUBY
end

run lambda { |env|
  parent_meminfo = Pitchfork::MemInfo.new(Process.ppid)
  siblings_pids = File.read("/proc/#{Process.ppid}/task/#{Process.ppid}/children").split
  siblings = siblings_pids.map do |pid|
    Pitchfork::MemInfo.new(pid)
  rescue Errno::ENOENT, Errno::ESRCH # The process just died
    nil
  end.compact

  total_pss = parent_meminfo.pss + siblings.map(&:pss).sum
  self_info = Pitchfork::MemInfo.new(Process.pid)

  body = <<~EOS
    Single Worker Memory Usage: #{(self_info.pss / 1024.0).round(1)} MiB
    Total Cluster Memory Usage: #{(total_pss / 1024.0).round(1)} MiB
  EOS

  App.warmup

  [ 200, { 'content-type' => 'text/plain' }, [ body ] ]
}

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
pitchfork-0.12.0 examples/constant_caches.ru
pitchfork-0.11.1 examples/constant_caches.ru
pitchfork-0.11.0 examples/constant_caches.ru
pitchfork-0.10.0 examples/constant_caches.ru
pitchfork-0.9.0 examples/constant_caches.ru
pitchfork-0.8.0 examples/constant_caches.ru
pitchfork-0.7.0 examples/constant_caches.ru
pitchfork-0.6.0 examples/constant_caches.ru
pitchfork-0.5.0 examples/constant_caches.ru
pitchfork-0.4.1 examples/constant_caches.ru
pitchfork-0.4.0 examples/constant_caches.ru
pitchfork-0.3.0 examples/constant_caches.ru
pitchfork-0.2.0 examples/constant_caches.ru
pitchfork-0.1.2 examples/constant_caches.ru
pitchfork-0.1.1 examples/constant_caches.ru