Skip to content

Is sendEachForMulticast thread safe #950

Closed

Description

@Laith-jalal

I was going through the sendEachForMulticast logic and didn't find anything to tell if it's thread safe or not, my current implementation is by calling the following in a new thread

FirebaseMessaging.getInstance().sendEachForMulticast(message)

Am I messing something here ? is my implementation thread safe ?

Activity

  1. google-oss-bot commented on May 22, 2024

    @google-oss-bot

    I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

  2. emindeniz99 commented on May 22, 2024

    @emindeniz99

    The method should not have any thread issue, because to achieve high notification throughput, we need to call the method in multiple thread.

    In production, we are using the predecessor "sendmulticast" method with 6+ thread to achieve 80k+ rpm on one java process. And we didn't face with any thread safety issue.

  3. meor9zcu12 commented on May 23, 2024

    @meor9zcu12

    When using FCM admin SDK v9.3.0 sendEach api with 20 threads, 500 tokens per thread, we encountered OutOfMemoryError,

    Caused by: java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached
    at java.base/java.lang.Thread.start0(Native Method)
    at java.base/java.lang.Thread.start(Thread.java:809)
    at java.base/java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:945)
    at java.base/java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1364)
    at com.google.common.util.concurrent.MoreExecutors$ListeningDecorator.execute(MoreExecutors.java:640)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
    at com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:79)
    at com.google.firebase.FirebaseApp.submit(FirebaseApp.java:384)
    at com.google.firebase.ImplFirebaseTrampolines.submitCallable(ImplFirebaseTrampolines.java:98)
    at com.google.firebase.internal.CallableOperation.callAsync(CallableOperation.java:47)
    at com.google.firebase.messaging.FirebaseMessaging$2.execute(FirebaseMessaging.java:227)
    at com.google.firebase.messaging.FirebaseMessaging$2.execute(FirebaseMessaging.java:222)
    at com.google.firebase.internal.CallableOperation.call(CallableOperation.java:36)
    at com.google.firebase.messaging.FirebaseMessaging.sendEach(FirebaseMessaging.java:189)

  4. emindeniz99 commented on May 23, 2024

    @emindeniz99

    When using FCM admin SDK v9.3.0 sendEach api with 20 threads, 500 tokens per thread, we encountered OutOfMemoryError,

    Caused by: java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached
    at java.base/java.lang.Thread.start0(Native Method)
    at java.base/java.lang.Thread.start(Thread.java:809)
    at java.base/java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:945)
    at java.base/java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1364)
    at com.google.common.util.concurrent.MoreExecutors$ListeningDecorator.execute(MoreExecutors.java:640)
    at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
    at com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:79)
    at com.google.firebase.FirebaseApp.submit(FirebaseApp.java:384)
    at com.google.firebase.ImplFirebaseTrampolines.submitCallable(ImplFirebaseTrampolines.java:98)
    at com.google.firebase.internal.CallableOperation.callAsync(CallableOperation.java:47)
    at com.google.firebase.messaging.FirebaseMessaging$2.execute(FirebaseMessaging.java:227)
    at com.google.firebase.messaging.FirebaseMessaging$2.execute(FirebaseMessaging.java:222)
    at com.google.firebase.internal.CallableOperation.call(CallableOperation.java:36)
    at com.google.firebase.messaging.FirebaseMessaging.sendEach(FirebaseMessaging.java:189)

    It is normal :). sendEachForMulticast has performance issues. The method creates a thread and opens a connection per device token. You can use old API until 20 June or try to limit concurrency or device token count. Concurrent sending requests should not be high, depending on your hardware, RAM and network socket limits.
    You can check the issue. #834 (comment)

  5. lahirumaramba commented on Sep 4, 2024

    @lahirumaramba
    Member

    Closing this as this will be addressed in #979

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions