I Have implemented the node js rest API. That being use in my android app with the help of Retrofit. Now. If my app is in production and then somehow my main server will be crash. So, in that case I have a backup server that will work same as the main server do.
So, How can I set an alternate base URL in retrofit android? So, If the main URL does not work then call all API from that alternate URL. Is there any build-it functionality?
Or most welcome for suggestions, Any other alternative ways to implement this.
I have another suggestion for you.
A NodeJS server should not stop for no reason. Most of the time, it's because of a 500 Error that have not been catched and stop the server. So, at first, make sure that every js command that may cause error is inside try/catch block.
Then, I suggest using of PM2 package
This is the best option to run on a production server.
It has several advantages:
It's easy to setup and run.
PM2 will automatically restart your application if it crashes.
PM2 will keep a log of your unhandled exceptions - in this case, in a
file at /home/safeuser/.pm2/logs/app-err.log.
With one command, PM2 can ensure that any applications it manages
restart when the server reboots. Basically meaning your node
application will start as a service.
ref: https://pm2.keymetrics.io/docs/usage/quick-start/
Related
I have built an application that calls a webservice in order to retrieve some information. This application is designed to work both on android and windows (using the firemonkey framework).
The object that calls the webservice has been built with a WSDL importer and works great when running the application on windows.
Nonetheless, when i try to use my application on an android device, i can only call the webservice two times. On the third time, the application freeze.
I have tried to do some debug and it appears that the application freezes when trying to call the web service :
genEtq := GetIGenerationEtiquettes(); // Converts a THttpRio as a IGenerationEtiquette object
soapattachmnt := genEtq.GetImageEtiquette(idEtiquette); // Calls web service -> freeze on third time
//
// Do something ...
//
The webservice is hosted on my computer so i'm sure there is no troubles on the service side. In addition, when i restart the application, i can still call the web service two times.
My application has the authorization to access to the internet on my android device so i'm running out of ideas on what's the problem.
Also i have tried to monitor the network (via wireshark) and i had been able to see the two first requests but not the third one.
Do you have any ideas on how to find the problem ?
Finally i have found the answer, my mistake was to call everytime the GetIGenerationEtiquettes() function instead of storing the resulting object.
Now i can call my webservice as often as i want.
Hope this answer will help someone.
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.
I am working on an android app in which I want all http request sent by android phone .Is it possible in android by creating a service?
You can create a service to do so, but it will make your code much more difficult, because services have different lifecycles than activities and fragments, they can exist even if the UI is not running. I give you the advice to handle it in your application code. One good library is OkHttp or if you want something more abstract you can go with Retrofit
I've written an android application, and I'd like to make it controllable to other machines by sending HTTP request to the device that run my application. I've written a tiny HTTP server and made it start when my application is started. I know I could translate HTTP requests and send messages to various activities to perform UI operations, that need to add listener to all my activities. But in order to make the remote controller code reusable, I hope separate remote controller code from existing application code and thus I need to find a way to make as less as change to the application code to make it be remote controllable.
Could anyone share your ideas?
I dont get what you are asking tbh but in one of application that my friend create, he just implement a mouse pointer which works from any android phone. With that application he can manage to use the android tv.
When he was implementing that app, he took advantage of socket programming and send messages from remote controller, in that situation a phone, to other device and fetch the data in there. In my opinion if you follow such a manner you just dont need to apply so many changes in your other applications. It is all communication in the end.
Currently i have an application where an activity calls a service which sends a file to a server. This is working fine..However, i was wondering does anybody know what happens if the internet connection is interrupted. Will the service run again when the connection comes back...Or is there something i need to implement to do this? If so how and what etc? thanks
The service will not run again when the connection comes back unless you add logic to do so. I'd recommend using a success flag to determine if a file was uploaded correctly, and if it wasn't due to an error (such as an interrupt), then you start the upload over again.
Perhaps alerting the user that a file upload has failed would be the best route to take, that way he/she can decide if its worth another try. This would also help keep your app from spiraling out of control while endlessly uploading a file to a server (although you could add a variable like maxNumberOfTries to avoid this).