11-14-2012 12:45 AM
Hi I'm a newbie... first time building an app with any real network connectivity and I'm seeing some terrible response times for content. I'm not sure if it's the networks out here or if that's just EDGE in general. It takes any where between 0.7-10 seconds to download a 3KB text file from the Internet. I'm at a loss at to where to start in terms of optimization. I figure on the server side I can do caching to ensure that as little processing as possible is happening on the server but what can I do on the client side? Compression? BIS? Any suggestions?
11-14-2012 03:38 AM
11-14-2012 06:16 AM
By PUSH do you mean Blackberry BIS? Is there a cost for this? Also, when you say control over client and server do you mean the phone and the server it's communicating with? We're building the app and we're writing the server side application. In that scenario, we have full control there... what options do we have there?
11-14-2012 06:57 AM
11-14-2012 09:57 AM
What do I need to do to use BIS? I was a bit unclear on that. Is BIS what Network Providers generally use? I read that BIS is automatic with a BES. I'm not hard and fast on "pulling", that just seemed like the logical way to do it coming from a normal web dev background.
How would BIS integration typically work? Is there a cost (financial) to the developer and if so, how is that usually managed? Is that usually pushed straight to the client? I really know nothing about BIS.
11-14-2012 10:22 AM
11-15-2012 04:47 PM
Is this normally the scenario? I gzipped content and decompressed it on the mobile and still had to wait up to 90 seconds for less than 1KB of data. TCP did the job in 2-5 or so seconds. I'm not sure I'll have time to negotiate BIS now in this stage of development
so I have to pull out all the big guns there are.
11-15-2012 06:42 PM
90 seconds for 1K seems like too much, I don't think it took that long in the old 2G days before things like EDGE!
I think you will have to time stamp the various phases of your operation and work out which component is taking the time. I would time stamp just before the open, just before getting the response code, just after you have downloaded the data (but before you decompress it) after you decompress it and so on. Can you do that with some sample code and show us where all the time is taken in the code?
11-16-2012 04:32 PM
Ok, here's the bulk of the code...
try {
HttpConnection httpConnection = (HttpConnection) connectionDescriptor
.getConnection();
// Set headers if GZIP is enabled...
if (useCompression) {
// httpConnection.setRequestMethod(HttpProtocolConsta
httpConnection.setRequestProperty(
HttpProtocolConstants.HEADER_USER_AGENT,
"Blackberry Device");
httpConnection.setRequestProperty(
"x-rim-transcode-content", "none");
httpConnection
.setRequestProperty(
HttpProtocolConstants.HEADER_CONTENT_TYPE,
HttpProtocolConstants.CONTENT_TYPE_APPLICATION_X_W
httpConnection.setRequestProperty(
HttpProtocolConstants.HEADER_ACCEPT_ENCODING,
"gzip");
}
// Go ahead and make the request!!!!
long startTime = System.currentTimeMillis(); // <!-- start tracking time for the request
int status = httpConnection.getResponseCode();
String contentEncoding = httpConnection.getEncoding();
long endTime = System.currentTimeMillis(); // <!-- stop tracking time for the request
if (status == HttpConnection.HTTP_UNAUTHORIZED) {
Utils.err("We cannot touch the Internet");
} else {
InputStream is = httpConnection.openInputStream();
String response;
byte[] rawData;
// Now check on the encoding...
if (contentEncoding != null
&& contentEncoding.equals("gzip")) {
// The data is compressed
long startUnzip = System.currentTimeMillis(); // <!-- start tracking time to un-gzip
GZIPInputStream gzipInputStream = new GZIPInputStream(
is);
rawData = net.rim.device.api.io.IOUtilities
.streamToBytes(gzipInputStream);
response = new String(rawData);
long endUnzip = System.currentTimeMillis(); // <!-- stop tracking time for un-gzip
Utils.log("Took us " + (endUnzip - startUnzip)
+ " ungzip response");
} else {
rawData = net.rim.device.api.io.IOUtilities
.streamToBytes(is);
response = new String(rawData);
}
// Now we have string and bytes saved
....
}
} catch (IOException ioe) {
Utils.err("Could not open a connection, IOException occurred. "
+ ioe.getMessage());
action.urlUnreachable();
}
Now I get the following output from that... Gzipping is fine, it usually takes just a couple ms. I've logged 3 requests below with the Gzip time. I logged file response size (in Bytes) and response time in ms. Notice the third request takes 38 seconds. This seems to happen every now and again.
Took us 10ms ungzip response
[TCP Cellular] [722B, 439ms]
Took us 3ms ungzip response
[TCP Cellular] [722B, 502ms]
Took us 6ms ungzip response
[TCP Cellular] [730B, 582ms]
Took us 8ms ungzip response
[TCP Cellular] [714B, 38019ms]
Took us 1ms ungzip response
[TCP Cellular] [774B, 653ms]
11-16-2012 06:30 PM
Can you extend the testing to d something like this and tell us what you see?
long startTime = System.currentTimeMillis();
long getCOnnectionTime, getResponseTime, getDataTime, unzipTime, responseTime;
HttpConnection httpConnection = (HttpConnection) connectionDescriptor
.getConnection();
getCOnnectionTime = System.currentTimeMillis();
// Set headers if GZIP is enabled...
if (useCompression) {
// httpConnection.setRequestMethod(HttpProtocolConsta
httpConnection.setRequestProperty(
HttpProtocolConstants.HEADER_USER_AGENT,
"Blackberry Device");
httpConnection.setRequestProperty(
"x-rim-transcode-content", "none");
httpConnection
.setRequestProperty(
HttpProtocolConstants.HEADER_CONTENT_TYPE,
HttpProtocolConstants.CONTENT_TYPE_APPLICATION_X_W
httpConnection.setRequestProperty(
HttpProtocolConstants.HEADER_ACCEPT_ENCODING,
"gzip");
}
// Go ahead and make the request!!!!
int status = httpConnection.getResponseCode();
String contentEncoding = httpConnection.getEncoding();
getResponseTime = System.currentTimeMillis();
if (status == HttpConnection.HTTP_UNAUTHORIZED) {
Utils.err("We cannot touch the Internet");
} else {
InputStream is = httpConnection.openInputStream();
String response;
byte[] rawData;
getDataTime = System.currentTimeMillis();
// Now check on the encoding...
if (contentEncoding != null
&& contentEncoding.equals("gzip")) {
// The data is compressed
GZIPInputStream gzipInputStream = new GZIPInputStream(
is);
rawData = net.rim.device.api.io.IOUtilities
.streamToBytes(gzipInputStream);
unzipTime = System.currentTimeMillis();
response = new String(rawData);
} else {
unzipTime = getDataTime;
rawData = net.rim.device.api.io.IOUtilities
.streamToBytes(is);
response = new String(rawData);
}
responseTime = System.currentTimeMillis();
// Now we have string and bytes saved
unzipTime = unzipTime - getDataTime;
getDataTime = getDataTime - getResponseTime;
getResponseTime = getResponseTime - getCOnnectionTime;
getCOnnectionTime = getCOnnectionTime - startTime;
Utils.log("Overall: " + responseTime - startTime) + "\n" +
" Connection: " + getCOnnectionTime + "\n" +
" Response: " + getResponseTime + "\n" +
" Data: " + getDataTime + "\n" +
" Unzip: + unzipTime);