I am connecting my iPhone application to JBOSS server. When the JBoss server is down, the iPHone timesout while connecting. It takes lot of time to timeout. Is there a quick way to identify if my application server is down. I think Reachability example demoes if the server machine is down and not if the application server is down. ANy help or advise would be appreciated.
Lets generalize the problem, so that its easier to visualize the problem and its solution.
Suppose, Your App is the only app connected to the server. When it sends a query, it get a response. Now you can assume if the server is OK, you should be able to receive a response in 5 sec's but if the server is down you will never receive a response.
This assumption breaks down the problem into two variables, 5 and infinity but you dont want to wait till the end of time to receive an answer, so you introduce a timeout value. Let say 5 min's. Now your variables are 5 and 360 sec. All is good but you dont want to wait 5 min (360 sec) if the server is down but you do want to wait 30 or 60 sec's if the connection is slow.
What you need is a another service, which monitors your server every (5-360) / 2 sec. Now when you query your server, you can wait till (5-360) / 2 sec before sending out a quick query to the third party service to check if your server is up or down.
This way you can reduce the query time out by (5-360) / 2 + the time it takes for the third party to answer your query.
See the docs on how to create your NSURLRequest: https://developer.apple.com/library/mac/ipad/#documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/Reference/Reference.html
You can specify a timeout with requestWithUrl:cachePolicy:timeoutInterval:
Related
I'm working with an API which only permits a maximum of 5 requests per second. If this limit is exceeded the API returns a 429 server error.
My intuition says that to handle this, I should put all requests into some form of serial queue, and enforce a delay of 0.21s between requests, but I'm not quite sure how to accomplish this. I'm also not sure if using a serial queue is a good idea, as then I'll lose the ability to have multiple requests running at the same time.
I am using adapter and retrier objects to handle refreshing my OAuth session token, so I guess this may be a good place to put my logic.
Has anyone done something like this before, or have any ideas?
Actually I'd probably go a different direction, rather than trying to throttle all requests, I'd look at the response from each request and if it's a 429, I'd re-queue the request via an async closure with a 1 second time delay.
This means that as long as requests are coming in slowly they are executed immediately. But when you try the 6th request, it's shifted into the next second.
The only problem you're going to have to consider (regardless of solution) is what happens if requests keep coming in faster than the API will allow. ie. what happens if you get 6, or 7 or 100 requests per second, for every second? How are you going to deal with the extra requests that will never get executed.
At some point your code is going to have to start failing requests. Alternatively you need to push the server people to run up more servers or give you more bandwidth.
Well, I browsed through the answers but none of them could solve the problem. When I hit the url for the first time, it takes very long time to boot up. The server response time is close to 30 sec (waiting time TTFB in chrome developer tool).
The subsequent requests are surprisingly faster. I don't think there's problem with the server side code as all the calls are taking this much time.
I don't think this is related to front end either as those contents are downloaded almost immediately.
Here's the link to my website http://nationposts.com
My app is able to consume a wcf using ASIHTTPRequest. But the thing is that i need to check the server hour every one minute. So i need a request to the server every one minute. What is more, sometime i will need to refresh the clock every one second.
the app is a items auction so i need to get the hour no matter what.
so my question is, is this going to kill the iphone?
ASIHTTPRequest have a method to achieve this? making calls every XX time?
some good way to do it?
Thx in advance!
Assuming the data you are getting back isn't larger than the memory threshold, and you are properly managing memory on your end, AND you are performing an asynchronous request (or a request on a background thread), this shouldn't kill the app memory-wise or cause it to hang.
I do something similar, where every 2 minutes I ping my server for updates. I achieve this using an NSURLConnection and NSURLRequest, though I imagine ASIHTTPRequest is not much different. I typically use a recurring timer that, when invoked, calls a method which, using Grand Central Dispatch, sets up my request/connection and fires.
I am working on some kind of communication which might get interrupted once in a while. For this I need some kind of monitor that fires after 5 seconds, if not in the meantime has been reset by any valid communication to start waiting for another 5 seconds, and so on....
Thanks!
Take a look at the NSTimer class.
I have been using SOAP to deal with Salesforce.com and have been using the getUpdated() call, using the timestamp I retrieve from the getServertimestamp() call.
I have watched my process check, (it polls every minute) and a few seconds after I save the change in the Sandbox environment, I see it poll, get no <ids> in the getUpdated call, and then on the next poll, the modified id shows up.
Is there a backend replication delay in SFDC? I suspect there is, but have had no luck in identifying the magnitude of it. Anyone else experienced this?
Additionally, I realize I should mention, this is all in a Sandbox copy of the environment, which may confuse matters even further.
Update: I just tested, and I made a change, and my poll ran 48 seconds later, and did not see the updated object. But 1 minute 48 seconds later it did see it. So that is one data point. (I know my SOAP endpoint and Web interface are both running on the same server at SFDC, tapp0).
There's no delay in the recording of the change, but the getUpdate/getDeleted calls round down the specified time to the nearest minute, so a finish time of now, gets rounded down, and the just made change falls outside of the range.
Also, if you're doing near realtime replication via these calls, then make sure to pay attention to the inflight transaction timestamp returned, otherwise you can miss changes (as the change timestamp can't be the actual transaction commit time)