简体   繁体   English

使用FCM向所有订阅主题的设备发送推送通知(批量)时出现缩放问题

[英]Scaling issue while sending push notifications (in bulk) to all the devices subscribed to a topic using FCM

I have subscribed all the devices to a topic ie around 1 million users . 我已经为所有设备订阅了一个主题,即大约100万用户 When notification is received in the device there is an action button which calls a REST api. 当设备中收到通知时,将有一个操作按钮,该按钮调用REST API。

Now if I trigger a notification to all the devices subscribed to the particular topic, all the users receive the notification and tap on the action button, which calls the rest API to fetch data. 现在,如果我向订阅该特定主题的所有设备触发通知,则所有用户都会收到该通知,然后点击操作按钮,该按钮将调用其余API来获取数据。

Too many rest API calls increase the CPU utilisation to 100% and my server stops responding. 太多的剩余API调用将CPU利用率提高到100%,并且我的服务器停止响应。

Is there any way I can made FCM to send notification to all the devices subscribed to a topic in the batches so that my server can handle the load 有什么办法可以使FCM将通知发送到批处理中订阅该主题的所有设备,以便我的服务器可以处理负载

Following solutions are workaround if there is no way to send the topic notification in the batch. 如果无法批量发送主题通知,则以下解决方案是解决方法。

1. Delaying the time of display of the notification at the app side. 1.延迟在应用程序一侧显示通知的时间。

After the notification received on the app, You can decide when to show it to user. 在应用程序上收到通知后,您可以决定何时向用户显示通知。 Write a logic in such way that, say some user will see the notification immediately as it received, some will see it after 2 minutes, some will see it after 4 minutes and so on. 以这样的方式编写逻辑,例如,某些用户将在收到通知后立即看到通知,有些用户将在2分钟后看到通知,有些用户将在4分钟后看到通知,依此类推。

You can use AlarmManager , Handler or something similar. 您可以使用AlarmManagerHandler或类似的东西。

2. Create bucket of the topics 2.创建主题组

Suppose you have a topic as sport_news . 假设您的主题为sport_news Divide the main topic sport_news into sport_news_1 , sport_news_2 , sport_news_3 and so on. 将主要主题sport_news分为sport_news_1sport_news_2sport_news_3等。 Implement your own logic to divide the users. 实施自己的逻辑来划分用户。

For example 例如

users registered in day 1 will fall into sport_news_1 第1天注册的用户将属于sport_news_1

users registered in day 2 will fall into sport_news_2 在第2天注册的用户将属于sport_news_2

and so on. 等等。

So whenever you have to send notification to topic sport_news then you will send the notification to all the topics belong to it, in our case it will be sport_news_1 , sport_news_2 and so on. 因此,无论何时必须将通知发送到sport_news主题,您都将向所有属于它的主题发送通知,在我们的示例中,它将是sport_news_1sport_news_2等。 You can send it on certain interval to handle the batches since you have the server side control to send it in the batches. 您可以按一定的间隔发送它以处理批处理,因为您具有服务器端控件来按批发送。

3. Scale the server for certain interval to handle the large traffic. 3.按一定间隔扩展服务器以处理大量流量。

After sending the notification to some million users and knowing you will get the high traffic then scale your server for certain time to handle the large traffic(say 1-2 hours). 在将通知发送给数百万用户并知道您将获得高流量后,请在一定时间内扩展服务器以处理大量流量(例如1-2小时)。

4. Improve the latency of your fetch data api 4.改善获取数据API的延迟

Knowing that you will get too many request for the particular fetch data api, You can implement caching, database indexing, in memory data store or any other way to speed up the fetch operation. 知道您会收到对特定提取数据api的过多请求,因此可以在内存数据存储中实现缓存,数据库索引或其他任何方式来加快提取操作。 You just have to find a way to reduce the response time for the fetch api in some way and your server will serve much traffic this way and cpu utilisation might reduced. 您只需要找到一种以某种方式减少fetch api响应时间的方法,您的服务器将以此方式处理大量流量,并且CPU利用率可能会降低。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM