C2DM sends messages slowly - java

I'm using C2DM in my application, and it works well, but sometimes, when I'm sending lots of messages, the delay is appearing, in it is up to 5 minutes.
All of my messages have the same collape key. Is it normal for C2DM?
EDIT: I'm sending approximately 1-2 messages per second
EDIT2: It is slow only for one device; another device receives notifications instantly

It is slow only for one device; another device receives notifications instantly
Probably due to network lags, you have to take network transience into account.
By the way, if you are sending 2 messages per second, your are sending 172800 messages to one device per day. You have a limit of 200,000 messages per day for one C2DM account. Clearly you aren't using C2DM the way it's supposed to be used. :)
Keep the application state in the server, not in the device, using a collapse key. So that only the most fresh result is delivered. Or else attenuation will be used to save battery.

Yep, as Reno linked to:
There is a attenuation. One post on Google Group suggest that each device has 20 tokens, and a new token is created every three minutes. So when you hit the limit, it'll take 3 minutes before you get the next token, thus the delay.
https://groups.google.com/forum/#!topic/android-c2dm/gY2RZBoFth4

Related

Discord bot - delay when sending messages [duplicate]

I want my discordbot to send send a message with an attached file in it and a text. Then the bot has to edit this text a couple of times but the problem is that when bot eddits message 5 times then it waits some time and then edits again 5 times etc etc. How can i make it edit messages without stopping?
if(msg.content.includes("letter")){
msg.channel.send("alphabet", { files: ["/Users/48602/Videos/discordbot/aaa.png"]})}
if(msg.content === 'alphabet'){
msg.edit("**a**")
msg.edit("**b**")
msg.edit("**c**")
msg.edit("**d**") // Here bot stop for a 2 seconds and i dont know why
msg.edit("**e**")
msg.edit("**f**")
msg.edit("**g**")
msg.edit("**h**")
msg.edit("**i**")
msg.edit("**j**")// Here bot stop for a 2 seconds and i dont know why
msg.edit("**k**")
msg.edit("**l**")
msg.edit("**m**")
msg.edit("**n**")
msg.edit("**o**") // Here bot stop for a 2 seconds and i dont know why
msg.delete()
}
Discord has a rate limit of 5 in each request. Trying to bypass this would be considered API abuse (the solutions later is not API abuse).
Exceeding this limit will pause other requests until a certain number of seconds has passed. Along with my research, I came across this simple explanation:
5 anything per 5 seconds per server (if you did not understand what I said above).
On Discord's Developer guide on rate limits, it tells you this:
There is currently a single exception to the above rule [rate limits] regarding different HTTP methods sharing the same rate limit, and that is for the deletion of messages. Deleting messages falls under a separate, higher rate limit so that bots are able to more quickly delete content from channels (which is useful for moderation bots).
One workaround, without API abusing, would be to send messages, and delete the previous messages since there is a higher limit for deleting messages.
Another workaround would be to add intermediate timeouts to your animation.
A simple method such as:
function async wait = { require("util").promisify(setTimeout); };
//syntax: await wait(1000); to "pause" for 1 second
You will need to play around with the timings so it fits your intended animation speed, and without pausing due to the rate limit.

Is there any way to know how much time Pushy(Java APNs library) will take to send 100K push notification?

I am working on testing the throughput for sending push notification using this library.
If anyone has any idea in this regard, a little guidance would be a great help.
Thanks.
Disclaimer: There is only an answer in form of a comment until now.
4s (in words: four seconds) seconds as indicated by XtremeBaumer.
By contrast, if we send notifications as quickly as we can without waiting for a reply (don't worry—the replies will arrive later), we can go much faster. Even though the server still takes 40 milliseconds to get back to us, we can keep working to send more notifications while we wait. In fact, we could theoretically send up to 25,000
notifications per second to the same server and under the same network conditions
Taken from https://github.com/relayrides/pushy/wiki/Best-practices
But be are that there might be other limiting factors in this calculation and this is a theorethical limit. Do a loadtest and you'll know for sure...

Configure app engine push task queue for twilio SMS verification

This question is a follow up to How to implement an atomic integer in Java App Engine?. Basically I am create a push Task Queue to implement SMS verification. I am using Twilio to send the SMS. Each SMS is a five digit pin number. The following is my queue.xml file for app-engine.
<queue-entries>
<queue>
<name>sms-verification</name>
<rate>200/s</rate>
<bucket-size>100</bucket-size>
<max-concurrent-requests>10</max-concurrent-requests>
</queue>
</queue-entries>
I want the best rate I can get without creating a new instance. I believe instance creation is expensive on app-engine, though I am not sure if it's the same for task queues. So is this configuration file good? Is it missing anything? This is my first time creating one so thanks for any guidance.
There is no right or wrong answer to this question. You will have to play with the configuration settings to get the optimal results for your requirements. You need to take the following into account:
You load throughout the day/week: more or less even or with sharp peaks.
Delay tolerance: how long it is acceptable to wait until the message is sent.
Obviously, it will be more expensive if you want to send all messages immediately, and less expensive if you can tolerate even a small delay (e.g. 1 minutes) as it would smooth out at least some sudden peaks.
Note that the higher the volume, the less important these optimizations become, as 1 new instance over 20 live is not as expensive as 1 new instance over 1.

How to implement an atomic integer in Java App Engine?

I am trying to roll out my own SMS verification system for my app. I don’t want to start paying for a service and then have them jack up the price on me (Urban Airship did that to me for push notification: lesson learned). During development and beta testing I have been using Twilio with a very basic setup: 1 phone number. It worked well for over a year, but right now for whatever reason the messages aren’t always delivered. In any case I need to create a better system for production. So I have the following specs in mind:
600 delivered SMS per minute
zero misses
save money
Right now my Twilio phone number can send one SMS per second; which means the best I can handle is 60 happy users per minute. So how do I get 600 happy users per minute?
So the obvious solution is to use 10 phone numbers. But how would I implement the system? My server is App Engine, DataStore, Java. So say I purchase 10 phone numbers from Twilio (fewer would of course be better). How do I implement the array so that it can handle concurrent calls from users? Will the following be sufficient?
public static final String[] phoneBank = {“1234567890”,”2345678901”,”3456789012”,”4567890123”,…};
public static volatile nextIndex;
public void sendSMSUsingTwilio(String message, String userPhone){
nextIndex = (nextIndex+1)%phoneBank.length;
String toPhone = phoneBank[nextIndex];
// boilerplate for sending sms with twilio goes here
//…
}
Now imagine 1000 users calling this function at the very same time. Would nextIndex run from 0,1,2…9,0,1…9,0,… successively until all requests are sent?
So really this is a concurrency problem. How will this concurrency issue work on Java AppEngine? Will there be interleaving? bottlenecking? I want this to be fast on a low budget: At least 600 per minute. So I definitely don’t want synchronization in the code itself to waste precious time. So how do I best synchronize calls to increment nextIndex so that the phone numbers are each called equally and in a periodic fashion? Again, this is for Google App Engine.
You need to use Task API. Every message is a new task, and you can assign phone numbers using round-robin or random assignments. As a task is completed, App Engine will automatically pull and execute the next task. You can configure the desired throughput rate (for example, 10 per second), and App Engine will manage the required capacity for you.
You can try to implement something similar on your own, but it's much more difficult than you think - you have to handle concurrency, retries, instance shutdowns, memory limits, etc. Task API does all of that for you.

Check database and receive android notification

I have a database with datas and my android application when it was launched checks if there is a new record in the database.
I created a Service and it checks every ten seconds if there is a new record and alert me with a notification.
I think it isn't the best solution cause it checks every ten seconds so it use the battery and internet every ten seconds.
Is there another solution to do that without check every ten seconds, for example, by using some code in my php form which add content in my database.
Thanks in advance.
You are right, there is plenty of solutions.
One of powerfull solutions is implementation of publish subscribe pattern.
In short: All subscribed clients will be notified on any change for which they are subscribed.
For quick info and start point use this link: https://developers.google.com/cloud/samples/mbs/pubsub_messaging.
General about publish subscribe: http://docs.oracle.com/cd/E19798-01/821-1841/bnced/index.html

Categories