Sha256: 6d78b80a4b9d7ee9a72c1f557c781f8333258d94844b491ff76df6f7853f5426

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

#!/usr/bin/env ruby

require 'pathname'
require 'benchmark'
require 'socket'
require 'fileutils'

root = Pathname.new(File.expand_path('../..', __FILE__))
TMP  = root.join("tmp/benchmark")
OUT  = TMP.join('out.txt')

FileUtils.rm_rf TMP
FileUtils.mkdir_p TMP
FileUtils.touch(OUT)

FWD = fork { exec "#{root}/bin/fwd-rb --flush 10000:2 -F tcp://0.0.0.0:7291 --path #{TMP} -v" }
NCC = fork { exec "nc -vlp 7291 > #{OUT}" }

sleep(5)

EVENTS = 10_000_000
LENGTH = 100
DATA   = "A" * LENGTH
CCUR   = 5

ds   = Benchmark.realtime do
  (1..CCUR).map do
    fork do
      sock = TCPSocket.new "127.0.0.1", 7289
      (EVENTS / CCUR).times { sock.write DATA }
      sock.close
    end
  end.each {|t| Process.wait(t) }
end

rs = Benchmark.realtime do
  while OUT.size < EVENTS * LENGTH
    sleep(1)
    puts "--> Written       : #{(OUT.size / 1024.0 / 1024.0).round(1)}M of #{(EVENTS * LENGTH / 1024.0 / 1024.0).round(1)}M"
  end
end

sleep(3)
puts "--> Dispatched in : #{ds.round(1)}s"
puts "--> Completed in  : #{(ds + rs).round(1)}s"
puts "--> FWD RSS       : #{(`ps -o rss= -p #{FWD}`.to_f / 1024).round(1)}M"
puts "--> Processed     : #{EVENTS} events"
puts "--> Written       : #{(OUT.size / 1024.0 / 1024.0).round(1)}M"

Process.kill(:TERM, FWD)
Process.kill(:TERM, NCC)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fwd-0.3.3 benchmark/performance.rb