Amazon SNS too slow and other issues
We are using Amazon SNS to send push notifications to mobile devices. So, just to check how it performs we tested it by creating 100K
random tokens, subscribing them to ten unique and random topics. 10K
s the maximum limit for a topic. We wanted to see '100K' delivery failure messages. So, to subscribe the token to the Application for which we want send push messages and to receive the end_point_arn
and then subscribe this end_point_arn
to a topic, if we do this for every topic one at a time , it would take maybe more than a day. Is it normal?
So, we tried implementing this paralleling using threads.
Here is my implementation :
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)
So, we have 10 topics here, each topic is being subscribed by 10K end_point_arn
. I run 100 thread. Where each thread subscribes `1K end_point_arn' to a topic.
And after aa couple of hours it threw an exception for each of the hundred thread.
Exception:
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
In between it also threw 403 Forbidden , for a few threads.
So, let's say I wanted send push messages to 100K
new user of my app, it will take me around a day to subscribe and send them? Or is there a way out. Why does this crash occurs?
上一篇: 使用aws sns从java web应用程序发送短信
下一篇: 亚马逊SNS太慢等问题