Hello Parse Community! I need your insights regarding this topic. I’ve been testing my app’s speed in fetching data through an API, and I’ve noticed that there is a speed difference between testing it on an Emulator and on a physical device. Also, there are times that data fetching on physical devices were quick and there are times when it’s not. I want to know if there are ways on how to make the speed consistent. I’ve come up with an option to store data to a local database and update the data when there are new objects created. Am I on the right track here? Or do I need to do something on my server to make the speed consistent?
I am using the flutter SDK and my server is self-hosted on the digital ocean. Thanks in advance!
Sorry for the later response. I have set up my parse server on a cloud server and I’ve been running the same query all the time. I am not sure and i cannot find any other ways to speed up my fetching aside from storing the query results to a local database. Even now I can still experience these instances.
There are many possible causes for performance variance. It can be as simple as network latency, or as complex as to how much of your working set (frequently accessed data) fits into the database RAM and whether the data you are fetching is currently in that working set.
The variance can occur in any or multiple of these components:
client app
client resources
network client <-> server
server resources
server app (Parse Server)
network server <-> database
database server resources
database server app (e.g. MongoDB)
To investigate that, you could start by directly load testing your server without using Parse Parse Server and without using a database. Then you gradually add more and more components until you reach your current configuration.
So after 3 days, I came back here for an update. I’ve created the server from scratch, also done doing some load testing, and deployed the server on a replica set. The server also uses an HTTPS connection. Now I’m in the process of testing basic queries on a freshly made server. And I’ve caught on something. I used ADB logcat to see what is really happening inside the physical device and on the emulator and they have one difference. I kept seeing these errors on the physical device.
The first one:
E[N rtchannel]_rt_mqtt_publish_callback(356)=>Failed to publish the request over MQTT. token:be925eea-407c-417d-96c9-3af5a7e83e48, category:mcd-sync-data-task-category, requestId:54138, error:Error Domain=mqtt Code=3008
W msgr.msys: W[S sync-state-machine]MCDSyncStateMachineScheduleDelayedRetry(173)=>skipping the new retry with longer delay
W msgr.msys: W[S sync]_scheduleNextCursorRetry(326)=>skipping delayed retry due to state machine state decision
The number of times these errors pop up is related to the number of queries executed. I have no idea what are those terms and I know that I need to research more regarding this but any help from you guys is much appreciated. If I’m not wrong, are these errors related to the server time or maybe the domain time? I don’t know yet. Thanks in advance.
You can try to run the load test in different environments, not in an emulator. It could be a constraint of network resources of the emulator. Which emulator is it?
Hi, @Manuel sorry for the late response. Just done redoing everything on your checklist except the 3rd and the 6th. I just wanted to know how and what are the things I need to check on the connection of the Client’s network to the Server and the server network to the database.
Client Network <-> Server
Here’s my configuration hope it might help:
Database: MongoDB replica Set
→ uses x509 certificates for the authentication
Deployment
->Nginx & Cloudflare(for the Hostname)
->Issued SSL Certificates on the hostname (LetsEncrypt)
Server Network to Database:
I’ve set up a firewall that has a rule that allows all of the members of the replica set to connect with each other’s MongoDB port and the IP address wherein the parse server is located. I can verify this as I can successfully add data.
Please bear with me. I want to really learn this one and I don’t know where to focus to reduce the response time of a query. I’m getting an average of 600ms on 10 tries just to get one customer info. I can share my configuration as I am totally new to this development environment.
For both, 3 and 6, you’d measure any variance in bandwidth and speed or general performance.
Average metrics are not a reliable basis for such an analysis. You’d want to especially look at percentiles, min and max.
What may help you is analyzing the transactions with a 3rd party service. There are sophisticated services available such as New Relic. They usually also allow you to measure in distributed systems to get a complete picture of where bottlenecks occur.
What you are looking for is a pattern of performance decrease and trying to reliably replicate that scenario to find out what causes it. It can be just a complex query that takes more time on the DB side and not be related to the infrastructure at all.
What kind of objects do you store in database? I believe you run emulator on PC with x86_64 cpu while your phone uses ARM cpu. They have different codecs. Maybe response of query contains something specific that pc cpu is good at decoding while mobile cpus having trouble? Just a guess? But still physical device is 10 times slower? thats odd.
I don’t have any complex queries as of the moment just a simple query with one where parameter. I’ll try to dive deeper using the tool you’ve mentioned
I’ve tried it also on other phones. Xiaomi Mi10T pro, Samsung s20pro and Xiaomi Redmi note 7. They have almost identical response times at an average of 500ms and a maximum of 1.5 seconds
I haven’t seen any data points yet that describe the variance your are referring to, but maybe it’s within normal range considering emulation?
However, you mentioned this also happens on physical devices.
I think to pursue this any further it would help to see the measurement you gathered so far and how and where you measured. It would also be good to know the scenarios in which you measured so far.
I suggest you strip everything and start with a simple express server without any database or Parse Server and load test your server. Preferably with a consistent load test to compare the results of each test. Then slowly add more. Some insight into what you have tested so far and your findings could help to suggest what to focus on.
Okay, so again, I tried to create another parse server app running at port 1338.
Flutter App has 6 queries.
I’m running the parse server without nginx and Cloudflare integrated. Just the bare IP address. And this is where I get good results. from a response time of 6-11 secs now it went down to 500ms - 700ms.
After integrating the default configuration of Nginx and Cloudflare with SSL, this is when the response time went back to 6-11 secs.
Now I know that the cause of my slow response times is because of Nginx and Cloudflare, my question is: When I go live, is it necessary to integrate Nginx and Cloudflare? And if yes, what is the best configuration for this.
Another thing worth mentioning here is when Nginx was integrated I notice a throttling on the client’s network speed.
without nginx - maximum of 15mbps
with nginx - maximum of 432kbps
Again, I dont know how to setup nginx for performance. I’ve followed some tutorials regarding Nginx Performance Optimization
Technically it may not be necessary. It may become necessary depending on your architecture, security or business considerations.
Nginx configuration is a science on its own. Nginx is a mammoth that is sometimes ambiguously documented. Depending on how you use it (load balancer, reverse proxy, etc.), things to look out for are usually timeouts, workers and file descriptor configurations. You may want to use a monitor like Amplify to look into what’s going on.
Maybe it helps you to further pin down which one of the two is causing the issue. My first suspicion would be Cloudflare, but it may well be nginx; I would not assume it is the interplay of both.
Yeah. I’m suspecting that too. I’ll come back here again after more testings. I will find first the cause of network speed throttling maybe it’s connected to one of them. Thank you for guiding me, man.