2

将数百万条消息推送到 HornetQ 的最快方法是什么?我有这两种方法:

1.)我当前的代码,为所有消息重用一个会话,ca。每秒 2.200 条消息

time = Benchmark.realtime do
  queue.with_session(:tx => false) do |session| 
    1_000_000.times do
      payload = Array.new(32){rand(36).to_s(36)}.join
      session.publish(queue, payload, queue.normalize_options(:persistent => false))
    end
  end
end
puts "Time elapsed #{time} seconds ..."

2.)优化的方式,但它在前 30k 条消息后挂起,直到每秒 9.000 条消息

time = Benchmark.realtime do
  queue.with_session(:tx => false) do |session|
    options = queue.normalize_options(:persistent => false)
    producer = session.instance_variable_get('@jms_session').create_producer(session.java_destination(queue))
    1_000_000.times do
      payload = Array.new(32){rand(36).to_s(36)}.join
      message = TorqueBox::Messaging::Message.new(session.instance_variable_get('@jms_session'), payload, options[:encoding])

      message.populate_message_headers(options)
      message.populate_message_properties(options[:properties])

      producer.disable_message_id = true
      producer.disable_message_timestamp = true

      producer.send( message.jms_message,
        options.fetch(:delivery_mode, producer.delivery_mode),
        options.fetch(:priority, producer.priority),
        options.fetch(:ttl, producer.time_to_live)
      )
    end
  end
end
puts "Time elapsed #{time} seconds …"

问题是,为什么第二个片段在 30k 之后挂起?对于 HornetQ 的大量插入,您有什么建议?

问候,克里斯

4

0 回答 0