Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 31
Registered: ‎11-14-2012
My Device: Blackberry 9780
My Carrier: Digicel

EDGE multipart upload pauses after a 1MB

Is there any reason why this would happen? Here is a snippet from the code I'm using for upload:

// Write headers and boundary etc...

// Store all the POST/GET data in an array...

byte[] finalData = bos.toByteArray();
bos.close();
int len = finalData.length;
int dataWritten = 0;
httpConnection.setRequestProperty(
HttpProtocolConstants.HEADER_CONTENT_LENGTH,
Integer.toString(len));

Utils.log("[Network] Opening outputstream to: " + originalUrl);
OutputStream os = httpConnection.openOutputStream();

while (dataWritten < len) {

 

int dataToWrite = Math.min(256, len - dataWritten);
os.write(finalData, dataWritten, dataToWrite);
dataWritten += dataToWrite;

final int currentProgress = dataWritten;
final int currentTotal = len;

if (dataWritten % (256 * 4 * 50) == 0) { // notify
// people
// every
// 50KB
// written
requestedProgressed(originalUrl, currentProgress,
currentTotal);
}
}

Utils.log("[Network] Closing outputstream to: " + originalUrl);

long startCloseStream = System.currentTimeMillis();
os.flush();
os.close();
long endCloseStream = System.currentTimeMillis();
Utils.log("[Network] Took " + (endCloseStream-startCloseStream)/1000 + "s to close output stream to " + url);
bos = null;
os = null;
finalData = null;
dataWritten = 0;

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: EDGE multipart upload pauses after a 1MB

I might be wrong, but I was under the impression that the stream connection was not actually established until you request something from the Server, like a response cide.  If this is true, then in this case, all you are doing is writing data to a buffer.  I am guessing that whoever developed this code probably did not expect anyone to write 1MB of data to a wireless connection, so perhaps there is some storage issue whereby it has to get another buffer which causes some memory stress.  It might be interesting to see the device log at this point to see if there is anything reported.

 

I would also argue that sending 1 MB in this way is probably not an effective approach.  I would suggest chunking the data up, which will reduce the memory footprint on device and also enable restart if there is a failure part way through.  Alternatively use something like a socket connection so that you can flush the data as you are going. 

 

But these are just musing really, I don't have  a proper answer sorry.

 

Can you give us more details, such as the OS you are testing, the device, if this is a Simulator or not, whether the server is connected at the time of the pause etc. 

Contributor
Posts: 31
Registered: ‎11-14-2012
My Device: Blackberry 9780
My Carrier: Digicel

Re: EDGE multipart upload pauses after a 1MB

Ohh... I was wrong then.. I saw openOutputStream and I thought... great... now I have a connection to the server and I'm writing data. No? I'm actually trying to upload an image, so I thought that I was already chunking up the data... and I'm literally at the end of this project now. How would I go about chunking it apart from just using getResponseCode or so? I'm testing this on OS 5 and 6 currently. It works fine in the simulator since I'm running over WiFi. No pauses on the phone over WiFi but only when the phone is running on EDGE. Re the server I'm a bit confused as to what's happening, because the server instantly gets to the point where it returns some JSON HTTP response but the phone takes forever to get it. So it's not like the server is stuck processing alot of stuff. 

 

 

 

Contributor
Posts: 31
Registered: ‎11-14-2012
My Device: Blackberry 9780
My Carrier: Digicel

Re: EDGE multipart upload pauses after a 1MB

Also... I find that on WiFi... it writes to the OutputStream much faster... why would that happen?
Contributor
Posts: 31
Registered: ‎11-14-2012
My Device: Blackberry 9780
My Carrier: Digicel

Re: EDGE multipart upload pauses after a 1MB

Just some more info here... I started printing out the free memory every now and then... it was down to 37MB when it paused first... it was back up to 57MB when it resumed... 

 

Additionally, lot's of stuff like this get's printed out... does this mean anything? This got printed out while I was waiting. 

[0.0] VM:+GC(f)w=9
[0.0] VM:-GCt=81,b=1,r=0,g=f,w=9
[0.0] VM:QUOT t=8
[0.0] VM:+RR
[0.0]
[0.0] RX=28.4M,RF=54.3M,FF=303.3M,OF=1M,OS=47.1M,ON=222K,OR=0,FR=70.9K,TR=107.7K,RR=3,IS=14.5K
[0.0] RA=64.5M,RS=47.1M,RN=150.8K
[0.0] TA=1M,TS=0,TN=5K
[0.0] PA=0,PS=0,PN=15.7K
[0.0] R0=59.7M,1=3.7M,2=20K,3=156.8K,4=1.9M,7=590.1K,8=6K,9=58.1M,10=23K,11=74.1K,12=482.3K,13=83.9K,14=2.[0.0] 4K,15=1017.3K,20=8K,21=780,22=92.3K,23=171.6K,24=22K
[0.0] FS: CLEAN(138 5)
[0.0] FS: CLEAN(649 5)
[0.0] FS: CLEAN(651 5)
[0.0] VM:-RR
[0.0]
[0.0] RX=28.4M,RF=54.7M,FF=302.9M,OF=1M,OS=46.7M,ON=222K,OR=0,FR=70.9K,TR=107.7K,RR=3,IS=14.5K
[0.0] RA=64.1M,RS=46.7M,RN=150.5K
[0.0] TA=1.3M,TS=0,TN=5.4K
[0.0] PA=0,PS=0,PN=15.7K
[0.0] R0=59.7M,1=3.7M,2=20K,3=156.8K,4=1.9M,7=590.1K,8=6K,9=57.7M,10=23K,11=74.1K,12=482.3K,13=83.9K,14=2.[0.0] 4K,15=1017.3K,20=8K,21=780,22=92.3K,23=171.6K,24=22K
[0.0] VM:+CR
[0.0] VM:-CR=47

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: EDGE multipart upload pauses after a 1MB

Looks like garbage collection to me...

 

The GC is definitely garbage collection, and guessing I think the f is a forced.

VM:+GC(f)w=9

There are a variety of different garbage collections run depending on how it is feeling.  It was explained at a session I went to in one of the Developer events, but that was a while ago and my memory is not that great....

 

I can't explain why WiFi would be faster, perhaps it has a bigger buffer?

 

Anyway, I think from this we can be confident your pause is garbage collection.  And there is not a lot you can do about it, except to send smaller files....