Sha256: f136f7c19f1d883389ec96ddb2069c41b00cecf654fe2ea909b4e2b095b9439f

Contents?: true

Size: 991 Bytes

Versions: 47

Compression:

Stored size: 991 Bytes

Contents

# frozen_string_literal: true

require 'fiber'

class Fiber
  attr_accessor :next
end

# This program shows how the performance of Fiber.transfer degrades as the fiber
# count increases

def run(num_fibers)
  count = 0

  GC.start
  GC.disable

  first = nil
  last = nil
  supervisor = Fiber.current
  num_fibers.times do
    fiber = Fiber.new do
      loop do
        count += 1
        if count == 1_000_000
          supervisor.transfer
        else
          Fiber.current.next.transfer
        end
      end
    end
    first ||= fiber
    last.next = fiber if last
    last = fiber
  end

  last.next = first

  t0 = Time.now
  puts "start transfer..."
  first.transfer
  elapsed = Time.now - t0

  rss = `ps -o rss= -p #{Process.pid}`.to_i

  puts "fibers: #{num_fibers} rss: #{rss} count: #{count} rate: #{count / elapsed}"
rescue Exception => e
  puts "Stopped at #{count} fibers"
  p e
end

puts "pid: #{Process.pid}"
run(100)
# run(1000)
# run(10000)
# run(100000)
# run(400000)

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
polyphony-1.6 examples/performance/fiber_transfer.rb
polyphony-1.5 examples/performance/fiber_transfer.rb
polyphony-1.4 examples/performance/fiber_transfer.rb
polyphony-1.3 examples/performance/fiber_transfer.rb
polyphony-1.2.1 examples/performance/fiber_transfer.rb
polyphony-1.2 examples/performance/fiber_transfer.rb
polyphony-1.1.1 examples/performance/fiber_transfer.rb
polyphony-1.1 examples/performance/fiber_transfer.rb
polyphony-1.0.2 examples/performance/fiber_transfer.rb
polyphony-1.0.1 examples/performance/fiber_transfer.rb
polyphony-1.0 examples/performance/fiber_transfer.rb
polyphony-0.99.6 examples/performance/fiber_transfer.rb
polyphony-0.99.5 examples/performance/fiber_transfer.rb
polyphony-0.99.4 examples/performance/fiber_transfer.rb
polyphony-0.99.3 examples/performance/fiber_transfer.rb
polyphony-0.99.2 examples/performance/fiber_transfer.rb
polyphony-0.99.1 examples/performance/fiber_transfer.rb
polyphony-0.99 examples/performance/fiber_transfer.rb
polyphony-0.98 examples/performance/fiber_transfer.rb
polyphony-0.97 examples/performance/fiber_transfer.rb