亚马逊SNS太慢等问题

我们正在使用Amazon SNS向移动设备发送推送通知。 因此,为了检查它的执行情况,我们通过创建100K随机令牌来测试它,并将它们订阅到10个独特而随机的主题。 10K s是主题的最大限制。 我们希望看到'100K'交付失败消息。 因此,要将令牌订阅到我们想要发送推送消息的应用程序并接收end_point_arn ,然后将此end_point_arn订阅到一个主题,如果我们一次一个地为每个主题执行此操作,则可能需要一天多的时间。 这是正常的吗?

所以,我们尝试使用线程来实现这个并行。

这是我的实现:

import redis_wrapper
from AiSns import AiSns
import time
import threading

from datetime import datetime
sns = AiSns(aws_access_key_id='********', aws_secret_access_key='********',region='us-east-1')
redis_sns_push_tokens = redis_wrapper.RedisSNSPushTokens()
redis_sns_apps = redis_wrapper.RedisSNSAPPS()
app_srn = '******'


class subscription_Thread (threading.Thread):
    def __init__(self, push_tokens, app_srn, topic_arn):
        threading.Thread.__init__(self)
        self.push_tokens = push_tokens
        self.app_srn = app_srn
        self.topic_arn = topic_arn
        aws_secret_access_key='AIjZCIEwWY7bK2g1cI7322VAIvQH1U5Ijdjpbcei',region='us-east-1')
    def run(self):
        subscribe(self.push_tokens, self.app_srn, self.topic_arn)



def subscribe(push_tokens, app_srn, topic_arn):

    for push_token in push_tokens:

        resp_data =  sns.subscribe_user_to_app(app_srn, push_token)
        end_point_arn = resp_data['CreatePlatformEndpointResponse']['CreatePlatformEndpointResult']['EndpointArn']
        subscribe_response = sns.subscribe_user_to_topic(topic_arn, end_point_arn)







tokens = []

test = 'Testing'

for i in range(0, 100000):
    tokens.append(test + '_' + str(i))

unique_topic = 'uniquetopic'
topic = []

for i in range(0, 10):
    topic.append(unique_topic + '_' + str(i))
#topics have been created

topic_arn = []
for a_topic in topic:

    resp_data = sns.create_new_topic(a_topic)
    topic_arn.append(resp_data['CreateTopicResponse']['CreateTopicResult']['TopicArn'])



threads = []
j = 0
for i in range(0, 100000, 1000):
    threads.append(subscription_Thread(tokens[i:i+999], app_srn, topic_arn[j]))
    if i != 0 and i%10000 == 0:
        j += 1

for thread in threads:
     thread.start()


for each_topic_arn in topic_arn:
     send_msg_response = sns.send_message_to_topic(each_topic_arn, 'Done', 'Test', 0)

所以,我们在这里有10个主题,每个主题都由10K end_point_arn订阅。 我跑100线程。 每个线程向某个主题订阅“1K end_point_arn”。

几个小时后,它为每一百个线程抛出一个例外。

例外:

Exception in thread Thread-99:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "yetAnotherTest.py", line 57, in run
    subscribe(self.push_tokens, self.app_srn, self.topic_arn)
  File "yetAnotherTest.py", line 65, in subscribe
    resp_data =  sns.subscribe_user_to_app(app_srn, push_token)
  File "/home/ubuntu/testing/AiSns.py", line 47, in subscribe_user_to_app
    attributes={'Enabled':enabled}
  File "/usr/lib/python2.7/dist-packages/boto/sns/connection.py", line 644, in create_platform_endpoint
    params=params)
  File "/usr/lib/python2.7/dist-packages/boto/sns/connection.py", line 727, in _make_request
    raise self.ResponseError(response.status, response.reason, body)
BotoServerError: BotoServerError: 400 Bad Request
None

在它之间,它也扔了403条Forbidden,只有几条线程。

所以,让我们说,我想发送推送消息到100K我的应用程序的新用户,它会带我身边,每天认购,并送他们? 或者有出路。 为什么会发生这种崩溃?

链接地址: http://www.djcxy.com/p/32235.html

上一篇: Amazon SNS too slow and other issues

下一篇: Amazon SNS dynamic topics case scenario