I am using geofire to retrive keys within a radius and need an help to understand how to profile it to cut costs.
Below the code I am using for key entered:
/**
How observers work for goquery
https://stackoverflow.com/questions/45179245/geofire-swift-3-cant-stop-observing
*/
var itemsProcessed = 0
self.circleQuery!.observe(.keyEntered, with: { (key: String!, location: CLLocation!) in
itemsProcessed = itemsProcessed + 1
NSLog("Controller | initiateGeoQuery | processed key \(itemsProcessed) with value: '\(key)', it has entered the search area and is at location '\(location)' , cirecleQuery has center: \(self.circleQuery!.center) , and radius: \(self.circleQuery!.radius)")
NSLog("AEViewController waiting 60 seconds before next key entered")
sleep(60)
In this test case I have 320 nodes outside the radius, located in China, and 2 nodes within the range, I am in EU.
I get the below output:
2020-02-15 15:01:55.198665+0000 Renal2[14181:706800] Controller | initiateGeoQuery | processed key 1 with value: 'Optional("adROWaUdK5gd6JKAfMW8DzfXpJB3")', it has entered the search area and is at location 'Optional(<xx.34939780,yy.23826435> +/- 0.00m (speed -1.00 mps / course -1.00) @ 15/02/2020, 15:01:55 Greenwich Mean Time)' , cirecleQuery has center: <xx.34939292,yy.23826781> +/- 65.00m (speed -1.00 mps / course -1.00) @ 15/02/2020, 15:01:54 Greenwich Mean Time , and radius: 50.0
2020-02-15 15:02:55.201683+0000 Renal2[14181:706800] Controller | initiateGeoQuery | processed key 2 with value: 'Optional("9fzIKheb8Ubvmu1tCA9V0uw0DOj1")', it has entered the search area and is at location 'Optional(<xx.34959316,yy.23812573> +/- 0.00m (speed -1.00 mps / course -1.00) @ 15/02/2020, 15:01:55 Greenwich Mean Time)' , cirecleQuery has center: <xx.34939292,yy.23826781> +/- 65.00m (speed -1.00 mps / course -1.00) @ 15/02/2020, 15:01:54 Greenwich Mean Time , and radius: 50.0
On Firebase profiler I have, for the first key entered :
┌────────────────────────────────────────────────┬───────────┬───────┬──────────┐
│ Path │ Total │ Count │ Average │
├────────────────────────────────────────────────┼───────────┼───────┼──────────┤
│ /GeoFire │ 118.72 kB │ 4 │ 29.68 kB │
For the second:
┌──────┬───────┬───────┬─────────┐
│ Path │ Total │ Count │ Average │
└──────┴───────┴───────┴─────────┘
This totally expected, and matches also GeoFire + Swift 3 can't stop observing
What is unexpected is that if I run the same test using 150 keys outside the radius instead of 320, the bandwidth is as per below:
┌───────────────────────────────────────────────────┬───────────┬───────┬──────────┐
│ Path │ Total │ Count │ Average │
├───────────────────────────────────────────────────┼───────────┼───────┼──────────┤
│ /GeoFire │ 56.04 kB │ 4 │ 14.01 kB │
Now, considering a real scenario in today business model where apps are global, is not uncommon to have let's say 1.000.000 keys spread around the world. As the ray in my case is about 50 Km, a realistic scenario is to have about 20/30 keys within the ray.
Do I have to pay for 1.000.000 x 0.36 KB , almost 370 MB? each session?
For sure I am doing something wrong here, per blog below
https://firebase.googleblog.com/2014/06/geofire-20.html
I can see:
GeoFire is smart about how it looks for keys within the query. It does not need to load all of the GeoFire data into memory. If your user is looking for bicycle shops in San Francisco, GeoFire will not load data for locations in New York only to realize that they are on the opposite side of the country. It only checks on locations which are actually nearby. This keeps your app light and responsive, regardless of how big your data set is.
When I started this project I was under the assumption that also the billing should have been light, can you please help me understand what I am doing wrong?
Thanks a lot.