I have a problem, when i startup my hybrid app. It takes very long to load the first page. ~40 seconds.
I work with GWT, Google App Engine and RequestFactories. I detected, that the app makes several request to the server (~ 10 requests).
Now i wonder, how can i increase the performance of staring up my app.
Group all request into one Request, which delivers all data with a single Request.
(~300kb data)
Make a startup page, with low amount of requests and data.
(~50kb data)
Better idea?
I prefer, that i can keep the current startup page. Can you share your experiance?
You have pointed out the two main ways to reduce the start-up time.
1.- Reduce requests: With RF you can group all requests in one if you share the same service instance and call only once the .fire() method. Use Bundles for images, css, and other resources so as them are downloaded in the same request.
2.- Reduce the js size: split your code in pieces using GWT.runAsync(). So the first piece of code could be the minimum stuff for starting your app until the user interacts with it. You can use the gwt compilation reports to see whether your code is bigger. You can use the new closure compiler in gwt-2.5 to reduce and optimize the final js.
3.- Another thing you must check is that your webserver configuration is sending the appropriate headers so as the browser caches gwt fragments, as well as you should check if it is compressing the files before sending to the client. You can make gwt compiler to pre-compress those js fragments though.
4.- For successive loads, I mean the user goes to your app a second time, consider using localstorage for caching certain things which don't change instead of requesting them again. Configure your HTML5Manifest, if you are using mgwt, it is really easy since they include a linker to produce the manifest in compile time.
5.- Consider using light-weight widgets and frameworks instead of heavy widgets (js collections, elemental, gquery, mgwt, etc).
I have several recommendation:
Load data that changed rarely in a single request at start up.
Activate GZip compression on your server.
Use background call when application start up finished in user idle time.
Group related request in a single request.
Related
I have an Android app Activity which fills a RecyclerView with some content from a DB hosted in Google's GCP CloudSQL. The data is served via a python flask app run by Google's AppEngine.
My problem is that some step or steps along the way from sending the GET request to having the RecyclerView inflated and full with the content introduce a heavy delay. The process takes about 10 to 12 seconds.
I have trouble understanding where the problem lies. I have tried the following and haven't been able to isolate a candidate for the delay. Taking into account that the Android app runs on an Android Studio emulator on my localhost:
If I run my flask app locally on my computer, but still request the data from the CloudSQL DB, the process is fast. So, it would seem that the problem is neither the DB nor the Android app RecyclerView inflating step (therefore, it must be the AppEngine flask app).
But if I run both the DB and the flask web server both on GCP and request the data via my web browser, I also get the data (JSON) fast. So, it would seem that the flask app hosted on GCP's AppEngine is also fine.
So, if according to the above tests all the three individual elements, the DB, the AppEngine Flask app and the RecyclerView inflation, all seem to behave good in terms of speed, why is it the chained process so slow in my app?
Most information out there for similar problems ascribe the slow response to AppEngine's cold start, but after many attempts, I am starting to think that this might not be my problem. Aside from the fact that, when I request the DB content via a web browser I get the response decently fast, I have checked and/or tested:
Reducing number of items in the list.
Setting the minimum number of instances to 1 + have enabled warmup requests (and my app processes them).
Setting the minimum number of idle instances to 1.
Use a WSGI production server (waitress) instead of the development flask service.
the AppEngine is located in "right" GCP Zone (europe-west-3). By "right" I mean the geographically closest to me, and the same region in which the CloudSQL DB is hosted.
Have set a "keep-alive" refresh cron job every minute to ensure no instance has to start cold.
Have tried going to manual scaling with one fixed instance.
None of the above solved the problem or reduced the total waiting time in the app. According to the AppEngine Dashboard, the loading latency of many requests is taking between 2 and 4 seconds, which is not the 10-12 seconds I have to wait on the Android app, but still seems abnormally, long taking into account all the measures in place for avoiding cold start (and, again, the fact that retrieving the DB info via web browser works at normal speed). This makes me think that either I have not successfully solved the cold start thing, or the latency problem lies elsewhere.
I am lost, and I do not know where to continue looking for issues. I would appreciate getting some tips in the right direction before I have to implement an in-device DB cache.
EDIT
Below there is a summary of HTTP request latencies to the web server (/refresh is the instance keep-alive resource, and /allrecords is an actual working endpoint). As it can be seen, the latencies are quite OK (which matches the good speed when retrieving the data via web browser).
I am quite confident the problem does not have to do with AppEngine cold start, so one would think the problem must lie within the Android app, but if I do the DB request via a web server in my local machine, the Android app works at normal speed.
EDIT 2
Retrieving info from the web server in JSON format via the web browser of the emulated device also works fast. So it does not seem to be a problem of the emulated device with internet connection speed.
I am deploying my Nodejs sample app to Google App Engine Flexible env and when I am using google app engine URL which is in the form appspot.com to hit my API, it is taking around 11 secs to send response from my mobile data, but other APIs are sending response in milisecs.
Also, the time delay is only happening when I am opening my android app and sending request to the server after that all requests are taking normal time, and again delay is coming when I again open the app and send request to the server.
Edit - I found that
This can be a caused when your application is still booting up or warming up instances to serve the request and can be called as loading latency. To avoid such scenarios you can implement health check handler like readiness check so that your application will only receive traffic when its ready
That's why I checked in my Logs that readiness check is performed sometimes around 1 sec
and sometimes around 200 ms
Can anyone please tell me is there anything wrong in warming up my instances because I don't think cold boot time is causing this problem.
Edit 2
I have also tried to set min_num_instances: 2 so that once loaded atleast my 2 instances will again not get boot up, but the thing is delay is again same.
Edit 3
runtime: nodejs
#vm: true
env: flex
automatic_scaling:
min_num_instances: 2
max_num_instances: 3
Edit 4
I am noticing a strange behaviour that when I am using this app Packet Capture to capture traffic, then all https requests (if I am not enabling SSL Proxying) and all Http requests are executing in milisecs whereas without using this app all Http/Https requests are taking 11-16 secs of delay.
I don't know how but is there any certificate kind of issue here?
Edit 5
Below I have attached Network Profiler where delay is coming 15 secs
Please Help
Depends on which App Engine you are using and how you setup the scaling, there's always a loading time if you don't have a ready instance to serve a request. But if you have readiness check to ensure your instance is ready (and not cold started for the request), then there shouldn't be a problem.
Can you find a loading request or any corresponding slow request in your logs? If not, then it's likely an issue with the app. If possible, instead of calling this API on your app, do it from two apps (one is already open, one is not). So you make calls from both apps and if you notice that the one that's already open is getting a response faster than the other one, that means that's a problem with the app itself. App Engine can't determine whether or not your app is pre-opened so any difference would be client side.
=== Additional information ===
In the your logs, there's no delay at all. The request enter Google and was processed within a few milliseconds. I am sure there's something application-side. Maybe your app is constructing the request URL (first request) from some other source that results in the delay? App Engine has no knowledge of whether or not your app is opened or not or whether it's sending a first request after being opened, it cannot act differently based on it. As long as your App Engine instance is ready and available, it will treat your request the same way regardless of whether or not it's your first request after the app is opened.
The issue is resolved now, it was happening because of network service provider which is Bharti Airtel, their DNS lookup was taking the time to resolve the hostname. After explicitly using alternative DNS like Google 8.8.8.8 the issue got completely resolved. Maybe it's a compatibility issue of Airtel with Google Cloud.
Last time I checked I remember having to put a warmup request handler so that Google would know that the instance is up and running and can be used to answer calls. Keep in mind that code has to be EXACTLY under the endpoint you specify in the handler under the yaml file. (Wouldn't be the first time someone forgets that)
Here are the docs https://cloud.google.com/appengine/docs/standard/python/configuring-warmup-requests this is python specific, but you can also check other languages like Go, Java, and such in the docs.
If the problem is client dependant (each time a new clients spawns and makes a call it gets the latency) then it is most likely, either a problem with the client app itself or with initialization, registration or DNS resolution.
You could also try to reproduce the requests with CURL or similar, and see if also with those you see the mentioned delay.
As far as I know, once you click "add to homescreen" on a PWA's website, the browser generates an .apk using the provided manifest file and sources and installs it like a normal app.
I noticed that when I update the website, the app also displays the updated content which suggests that the app is just a wrapper for accessing the website. I also noticed that the update to a website is not displayed instantly, I assume this is due to internal caching.
My question is, are my assumptions correct? Or more generally, when and how are PWAs updated and is there a way to force an update on a client machine?
No cache scenario (No Service worker): Your PWA app will be cached only when you use Service worker. Manifest.json will help adding your web app to home screen with a icon and open without address bar. If you don't have a service worker or if your browser don't support it, web page will be loaded fresh every single time. No Cache.
Cache-On Scenario (With Service worker): Assuming you have service workers configured, service workers can cache by lazy loading or prefetching the files that are configured for caching (You can include or exclude caching anything from html, CSS, images to JSON/XML API responses).
After the initial cache, service worker will use the cache to serve your apps network request based on cache approach you have implemented from below ones.
cache falling back to network
Network falling back to cache
Cache then network
Most apps choose to precache due to performance benefits and look for new files on loading, if any changes found will be loaded on next session or prompt user to refresh. With this solution, each file will have a long Hash string for each file cached by service worker. On load of each application, hash code from server will be fetched to match and find what file needs to be updated and the same will be updated in a separate service worker thread. You can notice this in network tab -> service worker response in chrome developer tools.
If you choose network-first approach, you can avoid showing old content on initial load, but loose significant performance benefits that comes with caching.
Only two events…
In essence, there are only two events that will automatically trigger a PWA update:
A change in the linked manifest.json; e.g. a changed icon file or a changed scope or start_url.
A one-character change in the controlling service-worker.js. Hence, if you store the version number in a const in this file and change it, an update of the PWA will be triggered.
When a change is detected, the new version will normally be activated only with the next PWA load. So, in all, two reloads are necessary to see a change.
How the update eventually is handled, is ultimately determined by the service-worker.js. Different update strategies may be defined in terms of the size and volatility of the PWA assets. It is also possible to activate a new service immediately.
However, there is one important caveat. Make sure that the browser cache expiry directive set by the .htaccess file of your asset server is set to a really short duration (e.g. hours) or even to none.
Failing to do so, will result in the browser not seeing any change for days to come in the manifest.json nor the service-worker.js.
More details about service worker behaviour are available from Google Web Fundamentals.
I am trying to test my webservice vs apps vs network performance. I have 3 team who is finger pointing each other for the Bad performance of the app. Webservice team says that the XML service returns data less than half second and App is taking long time to process the XML payload. The App team says that the webservice is slow to respond and app is loading data at 1 by 10 seconds. The QA guys says that both are faster, but the net is slow. Is there any tools to test the Apps fast vs Webservice Fast vs Network.
I would suggest to divide the tests before you are going to whole system performance test.
You have verify the load on each component independently from other components.
For example you can to develop the simple request simulator which will works against the web service. The simulator may be sets on the same LAN as the web service in order to avoid the network problems. Then you can measure the service responses stand alone. The same you can do with the App. Then if the both will work fast the network probably your problem.
The good and flexible new performance tool that I recommend is gatlink.
For the app side, you could at first simply add logs in your application. One log just before the HTTP request, one just after the response, then another just before parsing your payload and one after the parsing.
In these logs, you could write the current timestamp.
On a JBoss server, lies a JSP. Lets call it takestoolong.jsp
It does some processing that takes up to 30-45 seconds. (Yes, I know it should be optimized).
Then it returns. The 30-45 seconds is deemed too long for user experience for obvious reasons. So Akamai and load balancers are brought in so that this time can be reduced by caching the result of the request. At some point however, the jsp return content will change, and the cache will timeout. How do you prevent users from again seeing the 20-45 second download time? In particular how to you configure Akamai so that it does not use ip or other factors but returns processed result to the android device/user without the 30+ second delay? How to configure Akamai for Android devices?
My suggestion would be to isolate the takestoolong.jsp from the user all together, so that they only ever see the cached result....
to do that you'd want a secondary process that makes the request to the takestoolong.jsp page (it could be a simple cron job that hits the service and writes the result to an html page) and then point the users (or Akamai at the server delivering the static fragment of HTML.
that way you can refresh the results without the user seeing a delay and even when the content does change until the moment that the write is committed the user will still see the old content but no delay
[FWIW used this approach to deal with a similar issue ... huge, horribly complex SQL query that had to grab data from SQL Server then run a bunch of sub-queries against a MySQL database and consolidate the response. By using the intermediary output page and relying on IIS and browser caching caching that the users sometimes had slightly more stale data that was the absolute truth but they never got exposed to the actual response time of the underlying query]