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
New Developer
chris11
Posts: 57
Registered: ‎10-29-2008
My Device: Not Specified

Socket connection, sending data is really slow sometimes.

My client server app, device side code is like this and looping until all done.

 

socket= (SocketConnection) Connector.open(url, Connector.READ_WRITE);

socket.setSocketOption(SocketConnection.KEEPALIVE, 1);

outputstream = socket.openOutputStream();

inputstream = socket.openInputStream();

outputstream.write(rdata);

outputstream.flush();

 

server side C# code, I changed to like this for test.

  

 

while

(!requestdone)

{

 

try

{

 

if

(netSteam.DataAvailable)

{

 

int

rcnt = netSteam.Read(myReadBuffer, 0, myReadBuffer.Length);

 

if

(rcnt > 0)

{

 

ZenLog.logDebug("got data from device: " + rcnt);

 

}

}

 

 

}

 

catch (IOException e)

{

 

Log.logDebug("Socket read exception: " + e.Message);

 

break;

}

 

Thread

.Sleep(100);

}

 

 

device side log is attached at the end, from the log, you can see it took 39 seconds at 2009/10/23 09:53:45.484 to send 1806 bytes.  at 2009/10/23 09:52:58.149  it took 65 seconds. All other time it is very fast.

 

Can someone please help me understand what happening? Does it means that the fast one are not really sending, just buffering?

 

 

Server side seems to be getting data all the time, at around 1024 bytes per second(is  that typical speed for wireless carrier?)

 


2009/10/23 09:53:45.681 Sending : 2757 took 14ms
2009/10/23 09:53:45.640 Sending : 3715 took 27ms
2009/10/23 09:53:45.563 Sending : 3306 took 31ms
2009/10/23 09:53:45.484 Sending : 1806 took 39902ms---What is this 39 seconds?
2009/10/23 09:53:05.556 Sending : 1873 took 8ms
2009/10/23 09:53:05.518 Sending : 1240 took 10ms
2009/10/23 09:53:04.264 Sending : 1240 took 9ms
2009/10/23 09:53:04.229 Sending : 1806 took 9ms
2009/10/23 09:53:04.194 Sending : 1873 took 9ms
2009/10/23 09:53:04.157 Sending : 1240 took 10ms
2009/10/23 09:53:03.557 Sending : 1240 took 9ms
2009/10/23 09:53:03.521 Sending : 1806 took 9ms
2009/10/23 09:53:03.486 Sending : 1873 took 9ms
2009/10/23 09:53:03.451 Sending : 1240 took 10ms
2009/10/23 09:53:02.847 Sending : 1240 took 9ms
2009/10/23 09:53:02.812 Sending : 1806 took 9ms
2009/10/23 09:53:02.777 Sending : 1873 took 9ms
2009/10/23 09:53:02.741 Sending : 1240 took 9ms
2009/10/23 09:53:02.142 Sending : 1240 took 9ms
2009/10/23 09:53:02.108 Sending : 1806 took 9ms
2009/10/23 09:53:02.070 Sending : 1873 took 9ms
2009/10/23 09:53:02.032 Sending : 1240 took 9ms
2009/10/23 09:53:01.078 Sending : 1240 took 8ms
2009/10/23 09:53:01.042 Sending : 1806 took 9ms
2009/10/23 09:53:01.007 Sending : 1873 took 9ms
2009/10/23 09:53:00.970 Sending : 1240 took 9ms
2009/10/23 09:53:00.370 Sending : 1240 took 9ms
2009/10/23 09:53:00.334 Sending : 1806 took 10ms
2009/10/23 09:53:00.298 Sending : 1873 took 9ms
2009/10/23 09:53:00.263 Sending : 1240 took 8ms
2009/10/23 09:52:59.660 Sending : 1240 took 8ms
2009/10/23 09:52:59.625 Sending : 1806 took 9ms
2009/10/23 09:52:59.591 Sending : 1873 took 8ms
2009/10/23 09:52:59.555 Sending : 1240 took 8ms
2009/10/23 09:52:58.957 Sending : 1240 took 8ms
2009/10/23 09:52:58.922 Sending : 1806 took 8ms
2009/10/23 09:52:58.887 Sending : 1873 took 8ms
2009/10/23 09:52:58.853 Sending : 1240 took 9ms
2009/10/23 09:52:58.255 Sending : 1240 took 8ms
2009/10/23 09:52:58.221 Sending : 1806 took 8ms
2009/10/23 09:52:58.185 Sending : 1873 took 9ms
2009/10/23 09:52:58.149 Sending : 1240 took 65798ms-------What is this 65 seconds?
2009/10/23 09:51:51.756 Sending : 1240 took 8ms
2009/10/23 09:51:51.720 Sending : 1806 took 8ms
2009/10/23 09:51:51.684 Sending : 1873 took 8ms
2009/10/23 09:51:51.648 Sending : 1240 took 8ms
2009/10/23 09:51:51.038 Sending : 1240 took 9ms
2009/10/23 09:51:51.001 Sending : 1806 took 8ms
2009/10/23 09:51:50.964 Sending : 1873 took 9ms
2009/10/23 09:51:50.927 Sending : 1240 took 9ms
2009/10/23 09:51:50.328 Sending : 1240 took 9ms
2009/10/23 09:51:50.292 Sending : 1806 took 8ms
2009/10/23 09:51:50.255 Sending : 1873 took 8ms
2009/10/23 09:51:50.220 Sending : 1240 took 8ms
2009/10/23 09:51:49.611 Sending : 1240 took 9ms
2009/10/23 09:51:49.576 Sending : 1806 took 9ms
2009/10/23 09:51:49.541 Sending : 1873 took 9ms
2009/10/23 09:51:49.503 Sending : 1240 took 8ms
2009/10/23 09:51:48.908 Sending : 1240 took 8ms
2009/10/23 09:51:48.873 Sending : 1806 took 9ms
2009/10/23 09:51:48.838 Sending : 1873 took 9ms
2009/10/23 09:51:48.802 Sending : 1240 took 9ms
2009/10/23 09:51:48.201 Sending : 1240 took 9ms
2009/10/23 09:51:48.164 Sending : 1806 took 10ms
2009/10/23 09:51:48.129 Sending : 1873 took 9ms
2009/10/23 09:51:48.093 Sending : 1240 took 10ms
2009/10/23 09:51:47.494 Sending : 1240 took 9ms
2009/10/23 09:51:47.459 Sending : 1806 took 8ms
2009/10/23 09:51:47.424 Sending : 1873 took 8ms
2009/10/23 09:51:47.390 Sending : 1240 took 8ms
2009/10/23 09:51:46.067 Sending : 1240 took 10ms
2009/10/23 09:51:46.029 Sending : 1806 took 8ms
2009/10/23 09:51:45.990 Sending : 1873 took 9ms
2009/10/23 09:51:45.952 Sending : 1240 took 9ms
2009/10/23 09:51:45.342 Sending : 1240 took 9ms
2009/10/23 09:51:45.305 Sending : 1806 took 9ms
2009/10/23 09:51:45.268 Sending : 1873 took 8ms
2009/10/23 09:51:45.231 Sending : 1240 took 9ms
2009/10/23 09:51:44.618 Sending : 1240 took 8ms
2009/10/23 09:51:44.581 Sending : 1806 took 8ms
2009/10/23 09:51:44.544 Sending : 1873 took 8ms
2009/10/23 09:51:44.507 Sending : 1240 took 9ms
2009/10/23 09:51:43.892 Sending : 1240 took 8ms
2009/10/23 09:51:43.855 Sending : 1806 took 8ms
2009/10/23 09:51:43.818 Sending : 1873 took 9ms
2009/10/23 09:51:43.781 Sending : 1240 took 10ms
2009/10/23 09:51:43.167 Sending : 1240 took 9ms
2009/10/23 09:51:43.130 Sending : 1806 took 9ms
2009/10/23 09:51:43.093 Sending : 1873 took 8ms
2009/10/23 09:51:43.056 Sending : 1240 took 9ms
2009/10/23 09:51:42.442 Sending : 1240 took 7ms
2009/10/23 09:51:42.406 Sending : 1806 took 8ms
2009/10/23 09:51:42.368 Sending : 1873 took 9ms
2009/10/23 09:51:42.331 Sending : 1240 took 8ms
2009/10/23 09:51:41.723 Sending : 1240 took 8ms
2009/10/23 09:51:41.687 Sending : 1806 took 8ms
2009/10/23 09:51:41.650 Sending : 1873 took 9ms
2009/10/23 09:51:41.613 Sending : 1240 took 8ms
2009/10/23 09:51:41.008 Sending : 1240 took 8ms
2009/10/23 09:51:40.971 Sending : 1806 took 8ms
2009/10/23 09:51:40.935 Sending : 1873 took 9ms
2009/10/23 09:51:40.899 Sending : 1240 took 8ms
2009/10/23 09:51:40.296 Sending : 1240 took 8ms
2009/10/23 09:51:40.260 Sending : 1806 took 8ms
2009/10/23 09:51:40.224 Sending : 1873 took 8ms
2009/10/23 09:51:40.188 Sending : 1240 took 8ms

Please use plain text.
Developer
Aviator168
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: Socket connection, sending data is really slow sometimes.

What is in your URL and what kind of data plan do you have?

Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Socket connection, sending data is really slow sometimes.

[ Edited ]

I'm a bit suspicious of the fact that the client-side code is opening a connection without closing it and then also looping this whole construct "until its done". Moreover, it's not clear whether what's written into the output stream is a byte or an array of bytes, nor is it clear how the time measurement code is structured on the sending side.

 

P.S. Not sure why the KEEPALIVE setting needs touching for this scenario.

Please use plain text.
New Developer
chris11
Posts: 57
Registered: ‎10-29-2008
My Device: Not Specified

Re: Socket connection, sending data is really slow sometimes.

My bad, original post  was not clear enough.

 

device code is like this

 

url = "socket://" + rmserver + ":" + rmport +"deviceside=false";

socket = (SocketConnection) Connector.open(url,
       Connector.READ_WRITE);
     socket.setSocketOption(SocketConnection.KEEPALIVE, 1);

     outputstream = socket.openOutputStream();
     inputstream = socket.openInputStream();


while(!all_done)
{

//here prepare some data

long st = System.currentTimeMillis();

  outputstream.write(rdata);
  outputstream.flush();
Log.logDebug("Sending : " + rdata.length + " took " + (System.currentTimeMillis() - st) +  "ms");


}

 

 

My app is for enterprise users so I must use MDS.  I added ";deviceside=false" to url to enforce MDS use.

dataplan is att unlimited balckberry.

 

Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Socket connection, sending data is really slow sometimes.

When you encounter a super-slow write, what do the MDS logs show?

Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Socket connection, sending data is really slow sometimes.

P.S. Do you get similar results when connecting to a well-known working server, e.g., Netcat (nc -l -p <port>)?

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Socket connection, sending data is really slow sometimes.

Don't think you are actually measuring network communication at all here.

 

Reasons?

1) My experience with socket connections on BB is that, despite the flush, data is not necessarily sent until the Blackberry is requesting a response..  So until you issue a read on the inputstream, I think the data you are writing could be sitting on the device.  Might not be, might be waiting for a buffer/block to be full, however there is nothing in your code that will confirm it has been sent:

2) The consistency of the sending period, always seems t be about 8 ms (which is a relatively small interval to be measuring with a clock that is only accurate to millisecs)

3) The data rate - you have apparently sent 1240 byte sin 8 ms, which I think roughly equates to 155K per second.  You will be lucky to see this on a WiFi connection. 

 

This doesn't actually answer your question.  I suggest that to answer that, you should really run this on an attached device and watch out for log entries at the time of the delay.  Something like a Garbage collection could knock this processing for 6.  As could a buffer full condition on the socket which then forced all the data down the line and waited till it was clear before continuing.

 

Sorry not sure this helps much.

Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Socket connection, sending data is really slow sometimes.

peter_strange, flush() is not supposed to block until all the buffered data has actually been sent. It usually blocks only until all the buffered data has been moved into the transmit buffer of the network stack. So, it's pretty common to see write + flush take less than 10ms if the amount of buffered data is less than the size of the transmit buffer. As you correctly said though, if the network stack's transmit buffer becomes full (say because the data hasn't been transmitted or its delivery hasn't been confirmed), then write and/or flush will block until the congestion disappears.

 

I agree that it's a good idea to test whether the issue is due to congestion control (e.g., due to insufficient throughput due to overloaded network or frequent Tx/Rx errors). Try switching the Event Logger to Debug level to see whether these super-slow transmit events correlate with anything interesting in the log. MDS logs can also help to see what time, with what latency and at which intervals the transmitted data actually reaches the MDS.

Please use plain text.
Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Socket connection, sending data is really slow sometimes.

P.S. You can try to isolate cellular network effects from other effects by using the serial bypass: start the BlackBerry Device Manager (not the Desktop Manager!) on a PC (with Internet access), connect the BlackBerry over USB to the PC, wait until the Device Manager enables the bypass (there's a tab which shows this and also shows the amount of data passing through the bypass), disable the celluar and WiFi interfaces on the BlackBerry, and then re-run the test(s). The connection will be routed via the USB to the PC to the RIM's network infrastructure, and then to the BES/MDS.

 

Simiarly, you can see if it makes a difference when WiFi is used.

 

If you no longer get these super-slow transmit events, then, most likely the issue is due to throughput, Tx/Rx errors, or even temporary loss of connectivity on the cellular interface.

Please use plain text.
Developer
Aviator168
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: Socket connection, sending data is really slow sometimes.

Good to you can do that klyubin. I was working on TCP a few weeks ago with a send and a receive thread. I have the server keep sending data to the BB every half second and the BB sending to the server every half second. The receive thread works fine. However, the sending thread will stall after certain amount of data is send. I didn't how long it stalled as I kill process the server process when it started not receiving.

Please use plain text.