gpt4 book ai didi

java - Oracle Advanced Queue - 消耗率的性能问题

转载 作者:太空宇宙 更新时间:2023-11-04 13:18:56 25 4
gpt4 key购买 nike

我们在 Oracle 数据库环境中使用 Oracle Advanced Queue 执行了性能测试。我们使用以下脚本创建了队列和队列表:

    BEGIN

DBMS_AQADM.create_queue_table(
queue_table => 'verisoft.qt_test',
queue_payload_type => 'SYS.AQ$_JMS_MESSAGE',
sort_list => 'ENQ_TIME',
multiple_consumers => false,
message_grouping => 0,
comment => 'POC Authorizations Queue Table - KK',
compatible => '10.0',
secure => true);

DBMS_AQADM.create_queue(
queue_name => 'verisoft.q_test',
queue_table => 'verisoft.qt_test',
queue_type => dbms_aqadm.NORMAL_QUEUE,
max_retries => 10,
retry_delay => 0,
retention_time => 0,
comment => 'POC Authorizations Queue - KK');

DBMS_AQADM.start_queue('q_test');
END;

/

我们使用 PL/SQL 客户端以 2380 TPS 发布了 1000000 条消息。我们使用 Oracle JMS API 客户端以 292 TPS 消耗了 1000000 条消息。消费者速度几乎比发布者慢10倍,这个速度不符合我们的要求。

下面是我们用来消费消息的 Java 代码:

    if (q == null) initializeQueue();
System.out.println(listenerID + ": Listening on queue " + q.getQueueName() + "...");
MessageConsumer consumer = sess.createConsumer(q);

for (Message m; (m = consumer.receive()) != null;) {
new Timer().schedule(new QueueExample(m), 0);
}

sess.close();
con.close();

您对我们如何提高消费者端的性能有什么建议吗?

最佳答案

您对Timer的使用可能是您的首要问题。 Timer 定义如下:

Corresponding to each Timer object is a single background thread that is used to execute all of the timer's tasks, sequentially. Timer tasks should complete quickly. If a timer task takes excessive time to complete, it "hogs" the timer's task execution thread. This can, in turn, delay the execution of subsequent tasks, which may "bunch up" and execute in rapid succession when (and if) the offending task finally completes.

我建议您使用 ThreadPool .

// My executor.
ExecutorService executor = Executors.newCachedThreadPool();

public void test() throws InterruptedException {
for (int i = 0; i < 1000; i++) {
final int n = i;
// Instead of using Timer, create a Runnable and pass it to the Executor.
executor.submit(new Runnable() {
@Override
public void run() {
System.out.println("Run " + n);
}

});

}
executor.shutdown();
executor.awaitTermination(1, TimeUnit.DAYS);
}

关于java - Oracle Advanced Queue - 消耗率的性能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33285715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com