将数百万封邮件推送到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,你会推荐什么?
此致 克里斯