Hi,
In the past I have mentioned I had an issue with Firebase push notifications having a timeout issue per the following:
www.b4x.com
This is a follow up to that, as I am noticing something that may or may not be related.
On average by B4J app will send around 150 Firebase push notifications per minute.
I am using the code as per below.
The Topic, body, title and sound changes for each push notification. It only takes 0-1ms to generate these values, which is fine.
What I am finding is it's taking some time to process the SendMessage function. At the start the push notifications are fairly instant, and then all of a sudden it takes 10 seconds and then takes 1-2 minutes then around 20 minutes before I get the push notification on my phone.
For troubleshooting, I am logging how long it takes to run the 'Wait For' part of the code as per my code above.
Yesterday running the exact same code, it was logging around 300-400.
Today when I run the exact same code (made not programming changes) it seems to log 400, 570, 1246, 837, 833, 7745, 6620, 7261, 11715, 12307, 1692, 1198, 29010, 28248, 41720...
After around 5 minutes its logging around 160637, 164870, 173864..
I then moved the code I used to log how long it took to run the code, to the Sub SendMessage rather than logging after the 'Wait for', but it was logging roughly the same time. (so I assume it doesn't matter if I log it after the Wait For or in the sub since it returned the same value.
I am running the above on a AWS EC2 t3.medium using Ubuntu 22.04
As it started to run slow, I tried to run the code on another VPS with a different hosting company but have the same result.
I then ran the same code in the B4J IDE in release mode on my development machine, Windows 10 in a VM on my MacBook Pro and it seems to run fine. It logs 900-1200 in the IDE when it processes the messages. Which I would call acceptable as the push notification arrived within 1-2 seconds after the RunMe sub was called.
During all my tests it never logs any timeouts or errors, which is strange since it took longer to process but the timeout is set to 5000. So there must be something else causing it to run slow somewhere before it calls Job.PostString(..) as it was logging values more than the timeout value (5000).
I then logged to see how long the GetTokenValue took to get the value and it takes 30-40ms each time.
I am using B4J 10.00
Java jdk-14.0.1
I checked the internet speed on the AWS EC2 and it was as per below which I don't think is going to be the issue since my internet on my computer is a lot slower and it was working.
Download: 1911.46 Mbit/s
Upload: 1694.04 Mbit/s
Any ideas on where else to look to see why it's taking so long to run the code ?
In the past I have mentioned I had an issue with Firebase push notifications having a timeout issue per the following:
Sending Firebase Message - Object should first be initialized / timeout
Hi, I am running the following code to send a firebase push notification: Private Sub SendMessage(Topic As String, Title As String, Body As String, sound As String) As ResumableSub Dim Token As String = GetTokenValue(ServiceAccountFilePath) Dim Job As HttpJob Job.Initialize(""...
This is a follow up to that, as I am noticing something that may or may not be related.
On average by B4J app will send around 150 Firebase push notifications per minute.
I am using the code as per below.
The Topic, body, title and sound changes for each push notification. It only takes 0-1ms to generate these values, which is fine.
B4X:
Sub RunMe
Dim Topic as string = "test"
Dim Body as string = "Body test here"
Dim Title as string = "Title here"
dim sound as string = "default"
Dim n As Long = DateTime.now
Wait For (SendMessage(Topic, Title, Body, sound)) Complete (Success1 As Boolean)
Log("Total Time Took: " & (DateTime.Now - n))
End Sub
Public Sub SendMessage(Topic As String, Title As String, Body As String, sound As String) As ResumableSub
Try
Dim Token As String = GetTokenValue(ServiceAccountFilePath)
Dim Job As HttpJob
Job.Initialize("", Me)
Dim data As Map = CreateMap("title": Title, "body": Body)
Dim message As Map = CreateMap("topic": Topic, "data": data)
If Topic.StartsWith("ios_") Then
'B4i
Dim Badge As Int = 0
Dim iosalert As Map = CreateMap("title": Title, "body": Body)
message.Put("notification", iosalert)
message.Put("apns", CreateMap("headers": _
CreateMap("apns-priority": "10"), _
"payload": CreateMap("aps": CreateMap("sound": sound, "badge": Badge))))
Else
'B4A
message.Put("android", CreateMap("priority": "high"))
End If
Dim jg As JSONGenerator
jg.Initialize(CreateMap("message": message))
' Log("Sending")
' Log(jg.ToPrettyString(4))
Job.PostString($"https://fcm.googleapis.com/v1/projects/${ProjectID}/messages:send"$, jg.ToString)
Job.GetRequest.SetContentType("application/json;charset=UTF-8")
Job.GetRequest.SetHeader("Authorization", "Bearer " & Token)
Job.GetRequest.Timeout = 5000
Wait For (Job) JobDone(Job As HttpJob)
If Job.Success Then
'Log(Job.GetString)
Job.Release
Else
Log(Job.ErrorMessage)
Log("Failed to process Firebase. Topic = " & Topic)
Job.Release
End If
Job.Release
Return True
Catch
Job.Release
Log(LastException.Message)
Return False
End Try
End Sub
Private Sub GetTokenValue (FilePath As String) As String
Dim GoogleCredentials As JavaObject
GoogleCredentials.InitializeStatic("com.google.auth.oauth2.GoogleCredentials")
Dim Credentials As JavaObject = GoogleCredentials.RunMethodJO("fromStream", Array(File.OpenInput(FilePath, ""))) _
.RunMethod("createScoped", Array(Array As String("https://www.googleapis.com/auth/firebase.messaging")))
Credentials.RunMethod("refreshIfExpired", Null)
Return Credentials.RunMethodJO("getAccessToken", Null).RunMethod("getTokenValue", Null)
End Sub
What I am finding is it's taking some time to process the SendMessage function. At the start the push notifications are fairly instant, and then all of a sudden it takes 10 seconds and then takes 1-2 minutes then around 20 minutes before I get the push notification on my phone.
For troubleshooting, I am logging how long it takes to run the 'Wait For' part of the code as per my code above.
Yesterday running the exact same code, it was logging around 300-400.
Today when I run the exact same code (made not programming changes) it seems to log 400, 570, 1246, 837, 833, 7745, 6620, 7261, 11715, 12307, 1692, 1198, 29010, 28248, 41720...
After around 5 minutes its logging around 160637, 164870, 173864..
I then moved the code I used to log how long it took to run the code, to the Sub SendMessage rather than logging after the 'Wait for', but it was logging roughly the same time. (so I assume it doesn't matter if I log it after the Wait For or in the sub since it returned the same value.
I am running the above on a AWS EC2 t3.medium using Ubuntu 22.04
As it started to run slow, I tried to run the code on another VPS with a different hosting company but have the same result.
I then ran the same code in the B4J IDE in release mode on my development machine, Windows 10 in a VM on my MacBook Pro and it seems to run fine. It logs 900-1200 in the IDE when it processes the messages. Which I would call acceptable as the push notification arrived within 1-2 seconds after the RunMe sub was called.
During all my tests it never logs any timeouts or errors, which is strange since it took longer to process but the timeout is set to 5000. So there must be something else causing it to run slow somewhere before it calls Job.PostString(..) as it was logging values more than the timeout value (5000).
I then logged to see how long the GetTokenValue took to get the value and it takes 30-40ms each time.
I am using B4J 10.00
Java jdk-14.0.1
I checked the internet speed on the AWS EC2 and it was as per below which I don't think is going to be the issue since my internet on my computer is a lot slower and it was working.
Download: 1911.46 Mbit/s
Upload: 1694.04 Mbit/s
Any ideas on where else to look to see why it's taking so long to run the code ?