You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/08/14 16:51:38 UTC

[GitHub] [pulsar] GuoHaoZai opened a new pull request, #17092: [improve][broker]: DelayedDeliveryTracker init and addMessage

GuoHaoZai opened a new pull request, #17092:
URL: https://github.com/apache/pulsar/pull/17092

   ### Motivation
   
   improve DelayedDeliveryTracker perf
   
   ### Modifications
   
   1. PersistentDispatcherMultipleConsumers.java use double check lock init DelayedDeliveryTracker
   2. PersistentDispatcherMultipleConsumers.java not lock when msgMetadata.hasDeliverAtTime return false
   3. InMemoryDelayedDeliveryTracker.java `addMessage` method add lock to ensure thread safe
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   This change is already covered by existing tests:*org.apache.pulsar.broker.delayed.InMemoryDeliveryTrackerTest*. 
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): (yes / no)
     - The public API: (yes / no)
     - The schema: (yes / no / don't know)
     - The default values of configurations: (yes / no)
     - The wire protocol: (yes / no)
     - The rest endpoints: (yes / no)
     - The admin cli options: (yes / no)
     - Anything that affects deployment: (yes / no / don't know)
   
   ### Documentation
   
   Check the box below or label this PR directly.
   
   Need to update docs? 
   
   - [ ] `doc-required` 
   (Your PR needs to update docs and you will update later)
     
   - [x] `doc-not-needed` 
   (Please explain why)
     
   - [ ] `doc` 
   (Your PR contains doc changes)
   
   - [ ] `doc-complete`
   (Docs have been already added)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] coderzc commented on a diff in pull request #17092: [improve][broker]: DelayedDeliveryTracker init and addMessage

Posted by GitBox <gi...@apache.org>.
coderzc commented on code in PR #17092:
URL: https://github.com/apache/pulsar/pull/17092#discussion_r945464620


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/InMemoryDelayedDeliveryTracker.java:
##########
@@ -111,8 +111,10 @@ public boolean addMessage(long ledgerId, long entryId, long deliverAt) {
         }
 
 
-        priorityQueue.add(deliverAt, ledgerId, entryId);
-        updateTimer();
+        synchronized (this) {

Review Comment:
   > what do you think add synchronized to InMemoryDelayedDeliveryTracker#addMessage.
   
   Yes, I think can add `synchronized` to InMemoryDelayedDeliveryTracker#addMessage or add `synchronized` to 
   `PersistentDispatcherMultipleConsumers`
   
   > i have a question: InMemoryDelayedDeliveryTracker#getScheduledMessages is also need a synchronized ?
   
   I think`getScheduledMessages ` already add `synchronized ` on `PersistentDispatcherMultipleConsumers #getMessagesToReplayNow`:
   https://github.com/apache/pulsar/blob/825b68db7bed1c79af4b7b69b48bee76ebe75af5/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentStickyKeyDispatcherMultipleConsumers.java#L446-L457



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] GuoHaoZai commented on pull request #17092: [improve][broker]: DelayedDeliveryTracker init and addMessage

Posted by GitBox <gi...@apache.org>.
GuoHaoZai commented on PR #17092:
URL: https://github.com/apache/pulsar/pull/17092#issuecomment-1216559200

   > modify Motivation


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] coderzc commented on a diff in pull request #17092: [improve][broker]: DelayedDeliveryTracker init and addMessage

Posted by GitBox <gi...@apache.org>.
coderzc commented on code in PR #17092:
URL: https://github.com/apache/pulsar/pull/17092#discussion_r950585748


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/InMemoryDelayedDeliveryTracker.java:
##########
@@ -99,7 +100,7 @@ private long getCutoffTime() {
     }
 
     @Override
-    public boolean addMessage(long ledgerId, long entryId, long deliverAt) {
+    public synchronized boolean addMessage(long ledgerId, long entryId, long deliverAt) {

Review Comment:
   Ok, also add `synchronized` for the others method in the  `InMemoryDelayedDeliveryTracker`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] GuoHaoZai commented on a diff in pull request #17092: [improve][broker]: DelayedDeliveryTracker init and addMessage

Posted by GitBox <gi...@apache.org>.
GuoHaoZai commented on code in PR #17092:
URL: https://github.com/apache/pulsar/pull/17092#discussion_r948039461


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/InMemoryDelayedDeliveryTracker.java:
##########
@@ -99,7 +100,7 @@ private long getCutoffTime() {
     }
 
     @Override
-    public boolean addMessage(long ledgerId, long entryId, long deliverAt) {
+    public synchronized boolean addMessage(long ledgerId, long entryId, long deliverAt) {

Review Comment:
   In my opinion it is better to ensure thread safety by `DelayedDeliveryTracker` itself



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] github-actions[bot] commented on pull request #17092: [improve][broker]: DelayedDeliveryTracker init and addMessage

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #17092:
URL: https://github.com/apache/pulsar/pull/17092#issuecomment-1261657341

   The pr had no activity for 30 days, mark with Stale label.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] GuoHaoZai commented on a diff in pull request #17092: [improve][broker]: DelayedDeliveryTracker init and addMessage

Posted by GitBox <gi...@apache.org>.
GuoHaoZai commented on code in PR #17092:
URL: https://github.com/apache/pulsar/pull/17092#discussion_r945440111


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/InMemoryDelayedDeliveryTracker.java:
##########
@@ -111,8 +111,10 @@ public boolean addMessage(long ledgerId, long entryId, long deliverAt) {
         }
 
 
-        priorityQueue.add(deliverAt, ledgerId, entryId);
-        updateTimer();
+        synchronized (this) {

Review Comment:
   what do you think add `synchronized` to InMemoryDelayedDeliveryTracker#addMessage.
    
   and i have a question: InMemoryDelayedDeliveryTracker#getScheduledMessages is also need a `synchronized` ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] coderzc commented on pull request #17092: [improve][broker]: DelayedDeliveryTracker init and addMessage

Posted by GitBox <gi...@apache.org>.
coderzc commented on PR #17092:
URL: https://github.com/apache/pulsar/pull/17092#issuecomment-1229805180

   @Guohaozai, Do you have time to deal with this PR?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] MarvinCai commented on a diff in pull request #17092: [improve][broker]: DelayedDeliveryTracker init and addMessage

Posted by GitBox <gi...@apache.org>.
MarvinCai commented on code in PR #17092:
URL: https://github.com/apache/pulsar/pull/17092#discussion_r957265548


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/DelayedDeliveryTracker.java:
##########
@@ -31,6 +31,8 @@
 public interface DelayedDeliveryTracker extends AutoCloseable {
 
     /**
+     * may consider mark thread safe

Review Comment:
   we can't mark for an interface, I don't think this comment make sense here as we also can't guarantee implementation is thread safe



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/InMemoryDelayedDeliveryTracker.java:
##########
@@ -99,7 +100,7 @@ private long getCutoffTime() {
     }
 
     @Override
-    public boolean addMessage(long ledgerId, long entryId, long deliverAt) {
+    public synchronized boolean addMessage(long ledgerId, long entryId, long deliverAt) {

Review Comment:
   I don't think we need `synchronized` for all method in `InMemoryDelayedDeliveryTracker` though, we're not doing a big refactor here and just trying to avoid unnecessary synchronization if delayedDeliveryTracker already present right



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] coderzc commented on a diff in pull request #17092: [improve][broker]: DelayedDeliveryTracker init and addMessage

Posted by GitBox <gi...@apache.org>.
coderzc commented on code in PR #17092:
URL: https://github.com/apache/pulsar/pull/17092#discussion_r945407900


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/InMemoryDelayedDeliveryTracker.java:
##########
@@ -111,8 +111,10 @@ public boolean addMessage(long ledgerId, long entryId, long deliverAt) {
         }
 
 
-        priorityQueue.add(deliverAt, ledgerId, entryId);
-        updateTimer();
+        synchronized (this) {

Review Comment:
   I think it is not thread-safe when only lock this scope because `highestDeliveryTimeTracked` and `messagesHaveFixedDelay` will still be modified concurrently.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] coderzc commented on a diff in pull request #17092: [improve][broker]: DelayedDeliveryTracker init and addMessage

Posted by GitBox <gi...@apache.org>.
coderzc commented on code in PR #17092:
URL: https://github.com/apache/pulsar/pull/17092#discussion_r945464620


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/InMemoryDelayedDeliveryTracker.java:
##########
@@ -111,8 +111,10 @@ public boolean addMessage(long ledgerId, long entryId, long deliverAt) {
         }
 
 
-        priorityQueue.add(deliverAt, ledgerId, entryId);
-        updateTimer();
+        synchronized (this) {

Review Comment:
   > what do you think add synchronized to InMemoryDelayedDeliveryTracker#addMessage.
   
   Yes, I think can add `synchronized` to InMemoryDelayedDeliveryTracker#addMessage or add `synchronized` to 
   `PersistentDispatcherMultipleConsumers`.
   
   > i have a question: InMemoryDelayedDeliveryTracker#getScheduledMessages is also need a synchronized ?
   
   I think`getScheduledMessages` already add `synchronized` on `PersistentDispatcherMultipleConsumers #getMessagesToReplayNow`:
   https://github.com/apache/pulsar/blob/825b68db7bed1c79af4b7b69b48bee76ebe75af5/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentStickyKeyDispatcherMultipleConsumers.java#L446-L457



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] coderzc commented on a diff in pull request #17092: [improve][broker]: DelayedDeliveryTracker init and addMessage

Posted by GitBox <gi...@apache.org>.
coderzc commented on code in PR #17092:
URL: https://github.com/apache/pulsar/pull/17092#discussion_r946806761


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/InMemoryDelayedDeliveryTracker.java:
##########
@@ -99,7 +100,7 @@ private long getCutoffTime() {
     }
 
     @Override
-    public boolean addMessage(long ledgerId, long entryId, long deliverAt) {
+    public synchronized boolean addMessage(long ledgerId, long entryId, long deliverAt) {

Review Comment:
   I think it is best to use the same lock as `getScheduledMessages`. Keep use `synchronized(dispatcher)`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] coderzc commented on a diff in pull request #17092: [improve][broker]: DelayedDeliveryTracker init and addMessage

Posted by GitBox <gi...@apache.org>.
coderzc commented on code in PR #17092:
URL: https://github.com/apache/pulsar/pull/17092#discussion_r945464620


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/InMemoryDelayedDeliveryTracker.java:
##########
@@ -111,8 +111,10 @@ public boolean addMessage(long ledgerId, long entryId, long deliverAt) {
         }
 
 
-        priorityQueue.add(deliverAt, ledgerId, entryId);
-        updateTimer();
+        synchronized (this) {

Review Comment:
   > what do you think add synchronized to InMemoryDelayedDeliveryTracker#addMessage.
   
   Yes, I think can add `synchronized` to InMemoryDelayedDeliveryTracker#addMessage or add `synchronized` to PersistentDispatcherMultipleConsumers.
   
   > i have a question: InMemoryDelayedDeliveryTracker#getScheduledMessages is also need a synchronized ?
   
   I think`getScheduledMessages` already add `synchronized` on `PersistentDispatcherMultipleConsumers #getMessagesToReplayNow`:
   https://github.com/apache/pulsar/blob/825b68db7bed1c79af4b7b69b48bee76ebe75af5/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentStickyKeyDispatcherMultipleConsumers.java#L446-L457



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] GuoHaoZai commented on a diff in pull request #17092: [improve][broker]: DelayedDeliveryTracker init and addMessage

Posted by GitBox <gi...@apache.org>.
GuoHaoZai commented on code in PR #17092:
URL: https://github.com/apache/pulsar/pull/17092#discussion_r945508178


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/delayed/InMemoryDelayedDeliveryTracker.java:
##########
@@ -111,8 +111,10 @@ public boolean addMessage(long ledgerId, long entryId, long deliverAt) {
         }
 
 
-        priorityQueue.add(deliverAt, ledgerId, entryId);
-        updateTimer();
+        synchronized (this) {

Review Comment:
   add a new commit, please review again



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] GuoHaoZai closed pull request #17092: [improve][broker]: DelayedDeliveryTracker init and addMessage

Posted by GitBox <gi...@apache.org>.
GuoHaoZai closed pull request #17092: [improve][broker]: DelayedDeliveryTracker init and addMessage
URL: https://github.com/apache/pulsar/pull/17092


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org