Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore_: optimise publish envelope #5172

Merged
merged 1 commit into from
May 31, 2024
Merged

Conversation

qfrank
Copy link
Contributor

@qfrank qfrank commented May 16, 2024

When the publishEnvelope function encounters the error "not enough peers to publish," it's advisable not to increment the envelope.attempts counter within the EnvelopesMonitor.handleEnvelopeFailure method.

Summary of Changes

  1. New Fields in EnvelopesMonitor:

    • Added retryQueue field of type []*monitoredEnvelope to manage envelopes that need to be retried.
  2. New Methods:

    • backoffDuration(attempts int) time.Duration: Calculates the backoff duration based on the number of attempts.
    • retryLoop(): Handles the retry logic in a loop, triggered by a ticker every 500 milliseconds.
    • retryOnce(): Retries sending an envelope once, adhering to backoff logic.
    • removeFromRetryQueue(envelopeID types.Hash): Removes the specified envelope from the retry queue.
  3. Modified Methods:

    • Start(): Added a new goroutine to handle the retry logic using retryLoop().
    • Stop(): Now waits for both goroutines to finish using WaitGroup.
    • Add(): Now sets lastAttemptTime for new envelopes.
    • handleEnvelopeFailure(hash types.Hash, err error): Envelopes that need to be retried are now added to the retryQueue instead of being retried immediately.
  4. Miscellaneous:

    • Renamed some fields for better understanding
    • Set the lastAttemptTime field in monitoredEnvelope during creation and update.
    • Updated various logging statements to include more context.

These changes add a retry mechanism with exponential backoff to the EnvelopesMonitor, ensuring that envelopes are retried a limited number of times before being marked as expired. This should improve the reliability and robustness of the envelope handling process.

@qfrank qfrank self-assigned this May 16, 2024
@status-im-auto
Copy link
Member

status-im-auto commented May 16, 2024

Jenkins Builds

Click to see older builds (16)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 7d84d30 #1 2024-05-16 08:46:47 ~4 min linux 📦zip
✔️ 7d84d30 #1 2024-05-16 08:47:31 ~5 min ios 📦zip
✔️ 7d84d30 #1 2024-05-16 08:47:58 ~5 min android 📦aar
✖️ 7d84d30 #1 2024-05-16 09:21:04 ~38 min tests 📄log
✔️ cb96c84 #2 2024-05-20 08:02:38 ~2 min android 📦aar
✔️ cb96c84 #2 2024-05-20 08:02:44 ~2 min linux 📦zip
✔️ cb96c84 #2 2024-05-20 08:03:24 ~3 min ios 📦zip
✔️ 3e982d9 #3 2024-05-20 08:08:27 ~3 min ios 📦zip
✔️ 3e982d9 #3 2024-05-20 08:09:14 ~3 min linux 📦zip
✔️ 3e982d9 #3 2024-05-20 08:11:18 ~6 min android 📦aar
✔️ cb96c84 #2 2024-05-20 08:43:09 ~43 min tests 📄log
✔️ 3e982d9 #3 2024-05-20 09:27:50 ~44 min tests 📄log
✔️ dc41a41 #4 2024-05-29 03:55:09 ~3 min ios 📦zip
✔️ dc41a41 #4 2024-05-29 03:55:43 ~4 min linux 📦zip
✔️ dc41a41 #4 2024-05-29 03:57:07 ~5 min android 📦aar
✔️ dc41a41 #4 2024-05-29 04:36:10 ~44 min tests 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 29f7948 #5 2024-05-30 12:49:25 ~4 min linux 📦zip
✔️ 29f7948 #5 2024-05-30 12:50:26 ~5 min ios 📦zip
✔️ 29f7948 #5 2024-05-30 12:51:02 ~5 min android 📦aar
✔️ 29f7948 #5 2024-05-30 13:27:18 ~41 min tests 📄log

wakuv2/waku.go Outdated Show resolved Hide resolved
wakuv2/waku.go Outdated Show resolved Hide resolved
wakuv2/waku.go Outdated Show resolved Hide resolved
@qfrank
Copy link
Contributor Author

qfrank commented May 16, 2024

Hi @richard-ramos, appreciate your feedback. The initial motivation behind creating this PR was to address the potential issue of encountering the error "not enough peers to publish" multiple times in quick succession. This could lead to a situation where handleEnvelopeFailure retries immediately after the error occurs, while the underlying problem of "not enough peers to publish" may not be resolved promptly. Consequently, this could result in envelope.attempts reaching maxAttempts too quickly.

With your insights, things are clearer now. I believe the best approach to prevent envelope.attempts from reaching maxAttempts too rapidly is to implement a backoff mechanism linked to envelope.attempts. I'll incorporate this into my PR tomorrow. Thanks again for your input. WDYT? @richard-ramos cc @chaitanyaprem

@chaitanyaprem
Copy link
Contributor

Hi @richard-ramos, appreciate your feedback. The initial motivation behind creating this PR was to address the potential issue of encountering the error "not enough peers to publish" multiple times in quick succession. This could lead to a situation where handleEnvelopeFailure retries immediately after the error occurs, while the underlying problem of "not enough peers to publish" may not be resolved promptly. Consequently, this could result in envelope.attempts reaching maxAttempts too quickly.

With your insights, things are clearer now. I believe the best approach to prevent envelope.attempts from reaching maxAttempts too rapidly is to implement a backoff mechanism linked to envelope.attempts. I'll incorporate this into my PR tomorrow. Thanks again for your input. WDYT? @richard-ramos cc @chaitanyaprem

This approach sounds good to me as well.

@qfrank qfrank force-pushed the chore/optimise_waku_broadcast branch from 7d84d30 to cb96c84 Compare May 20, 2024 07:59
@qfrank qfrank force-pushed the chore/optimise_waku_broadcast branch from cb96c84 to 3e982d9 Compare May 20, 2024 08:04
@qfrank qfrank force-pushed the chore/optimise_waku_broadcast branch from dc41a41 to 29f7948 Compare May 30, 2024 12:45
@qfrank qfrank merged commit 0a88ebd into develop May 31, 2024
12 checks passed
@qfrank qfrank deleted the chore/optimise_waku_broadcast branch May 31, 2024 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants