james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [2/2] james-project git commit: JAMES-2550 Fix MAJOR performance problem upon RabbitMQMailQueue::dequeue
Date Thu, 29 Nov 2018 11:02:05 GMT
JAMES-2550 Fix MAJOR performance problem upon RabbitMQMailQueue::dequeue

Currently using the delete method as part of dequeue **we do read all the mailqueue content**
on each, and every dequeued mails, causing major performance issue.

As a remider, we never end up browsing while dequeuing a mail from RabbitMQ.

This commit fixes this.


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/00302ef3
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/00302ef3
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/00302ef3

Branch: refs/heads/master
Commit: 00302ef31a1aefa77b9c00246602f7a3c62fccd6
Parents: 1d57440
Author: Benoit Tellier <btellier@linagora.com>
Authored: Tue Nov 27 11:55:27 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Nov 29 18:01:28 2018 +0700

----------------------------------------------------------------------
 .../queue/rabbitmq/view/api/DeleteCondition.java     |  4 ++++
 .../view/cassandra/CassandraMailQueueMailDelete.java |  6 +++++-
 .../view/cassandra/CassandraMailQueueView.java       | 15 +++++++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/00302ef3/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/api/DeleteCondition.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/api/DeleteCondition.java
b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/api/DeleteCondition.java
index 4424750..96060dd 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/api/DeleteCondition.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/api/DeleteCondition.java
@@ -86,6 +86,10 @@ public interface DeleteCondition {
             this.name = name;
         }
 
+        public String getName() {
+            return name;
+        }
+
         @Override
         public boolean shouldBeDeleted(Mail mail) {
             Preconditions.checkNotNull(mail);

http://git-wip-us.apache.org/repos/asf/james-project/blob/00302ef3/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailDelete.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailDelete.java
b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailDelete.java
index 4a9ee83..b94b1ed 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailDelete.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailDelete.java
@@ -54,8 +54,12 @@ public class CassandraMailQueueMailDelete {
     }
 
     CompletableFuture<Void> considerDeleted(Mail mail, MailQueueName mailQueueName)
{
+        return considerDeleted(MailKey.fromMail(mail), mailQueueName);
+    }
+
+    CompletableFuture<Void> considerDeleted(MailKey mailKey, MailQueueName mailQueueName)
{
         return deletedMailsDao
-            .markAsDeleted(mailQueueName, MailKey.fromMail(mail))
+            .markAsDeleted(mailQueueName, mailKey)
             .thenRunAsync(() -> maybeUpdateBrowseStart(mailQueueName));
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/00302ef3/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueView.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueView.java
b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueView.java
index 5f9b8f5..4980f46 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueView.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueView.java
@@ -32,6 +32,7 @@ import org.apache.james.queue.rabbitmq.view.api.MailQueueView;
 import org.apache.james.queue.rabbitmq.view.cassandra.configuration.CassandraMailQueueViewConfiguration;
 import org.apache.james.queue.rabbitmq.view.cassandra.configuration.EventsourcingConfigurationManagement;
 import org.apache.james.queue.rabbitmq.view.cassandra.model.EnqueuedItemWithSlicingContext;
+import org.apache.james.queue.rabbitmq.view.cassandra.model.MailKey;
 import org.apache.james.util.FluentFutureStream;
 import org.apache.mailet.Mail;
 
@@ -105,6 +106,16 @@ public class CassandraMailQueueView implements MailQueueView {
 
     @Override
     public CompletableFuture<Long> delete(DeleteCondition deleteCondition) {
+        if (deleteCondition instanceof DeleteCondition.WithName) {
+            DeleteCondition.WithName nameDeleteCondition = (DeleteCondition.WithName) deleteCondition;
+
+            return delete(MailKey.of(nameDeleteCondition.getName())).thenApply(any ->
1L);
+        }
+
+        return browseThenDelete(deleteCondition);
+    }
+
+    private CompletableFuture<Long> browseThenDelete(DeleteCondition deleteCondition)
{
         CompletableFuture<Long> result = cassandraMailQueueBrowser.browseReferences(mailQueueName)
             .map(EnqueuedItemWithSlicingContext::getEnqueuedItem)
             .filter(mailReference -> deleteCondition.shouldBeDeleted(mailReference.getMail()))
@@ -118,6 +129,10 @@ public class CassandraMailQueueView implements MailQueueView {
         return result;
     }
 
+    private CompletableFuture<Void> delete(MailKey mailKey) {
+        return cassandraMailQueueMailDelete.considerDeleted(mailKey, mailQueueName);
+    }
+
     @Override
     public CompletableFuture<Boolean> isPresent(Mail mail) {
         return cassandraMailQueueMailDelete.isDeleted(mail, mailQueueName)


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message