Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

out_copy: Add copy_mode parameter. fix #2744 #2747

Merged
merged 1 commit into from
Dec 25, 2019

Conversation

repeatedly
Copy link
Member

@repeatedly repeatedly commented Dec 24, 2019

Signed-off-by: Masahiro Nakagawa [email protected]

Which issue(s) this PR fixes:
Fixes #2744

What this PR does / why we need it:
Add copy_mode parameter to control no / shallow / deep copy.

Here is benchmark code:

require 'benchmark/ips'
require 'active_support/core_ext/object/deep_dup'
require 'fluent/event'
require 'fluent/time'
require 'msgpack'

test1 = Fluent::MultiEventStream.new
100.times { |i|
  record = {"time" => 1362020400,"host" => "192.168.0.1","size" => 777,"method" => "PUT", "kubernetes" => {"pod" => "test", "labels" => {"app" => "foo"}}}
  test1.add(Fluent::EventTime.now, record)
}

def f_n(es)
  es
end

def f_d(es)
  es.dup
end

def f_dd(es)
  new_es = Fluent::MultiEventStream.new
  es.each { |time, record|
    new_es.add(time, record.deep_dup)
  }
  new_es
end

def f_mp(es)
  new_es = Fluent::MultiEventStream.new
  es.each { |time, record|
    new_es.add(time, MessagePack.unpack(MessagePack.pack(record)))
  }
  new_es
end

def f_mp2(es)
  packer = Fluent::MessagePackFactory.msgpack_packer
  times = []
  records = []
  es.each { |time, record|
    times << time
    packer.pack(record)
  }
  Fluent::MessagePackFactory.msgpack_unpacker.feed_each(packer.full_pack) { |record|
    records << record
  }
  Fluent::MultiEventStream.new(times, records)
end

def f_m(es)
  new_es = Fluent::MultiEventStream.new
  es.each { |time, record|
    new_es.add(time, Marshal.load(Marshal.dump(record)))
  }
  new_es
end

Benchmark.ips do |x|
  x.report "none" do
    f_n(test1)
  end

  x.report "dup" do
    f_d(test1)
  end

  x.report "deep_dup" do
    f_dd(test1)
  end

  x.report "msgpack" do
    f_mp(test1)
  end

  x.report "msgpack2" do
    f_mp2(test1)
  end

  x.report "marshal" do
    f_m(test1)
  end
end

result:

Warming up --------------------------------------
                none   375.217k i/100ms
                 dup     2.231k i/100ms
            deep_dup   241.000  i/100ms
             msgpack   215.000  i/100ms
            msgpack2   525.000  i/100ms
             marshal    78.000  i/100ms
Calculating -------------------------------------
                none     18.437M (± 5.8%) i/s -     91.928M in   5.007073s
                 dup     22.413k (± 5.7%) i/s -    113.781k in   5.095399s
            deep_dup      2.436k (± 5.9%) i/s -     12.291k in   5.065170s
             msgpack      2.163k (± 6.8%) i/s -     10.750k in   5.000194s
            msgpack2      5.314k (± 6.4%) i/s -     26.775k in   5.063501s
             marshal    784.487  (± 5.1%) i/s -      3.978k in   5.086555s

Docs Changes:
Add copy_mode parameter.

Release Note:
Same as title.

@repeatedly repeatedly added the enhancement Feature request or improve operations label Dec 24, 2019
@repeatedly repeatedly requested a review from ganmacs December 24, 2019 09:59
@repeatedly repeatedly self-assigned this Dec 24, 2019
@repeatedly repeatedly merged commit b9089ed into master Dec 25, 2019
@repeatedly repeatedly deleted the out_copy-add-copy_mode branch December 25, 2019 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request or improve operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@copy deep_copy does not work
2 participants