M
Michael
Hi all,
I am using Java DataInputStram and DataOutputStream to send a large file
thorugh Internet. When I test it with local LAN, the speed is fairly
fast and acceptable. With the same testing PCs and programs, I send the
file through Intenet, using ADSL boardband modem. I found that the speed
is as low as 15k to 17k byte per second. The bottleneck seems to be the
uplink side.
I am using 1.5Mb (bits per second) ISP service. The actual uplink speed
when I am using some network monitor tools is 27k to 59k byte per second
on average. That means, my program is running too slow when transfering
data through Internet.
My upload program is :
while (myfile_BufferedInputStream.read(buffer, 0, buffer_size) != -1) {
myInternet_DataOutputStream.write(buffer, 0, buffer_size);
// calculate and display the speed
// some debug message...
}
My download program is :
while (!EOF_flag) {
int n, total_length, actual_read = 0;
while (n < buffer_size && actual_read >= 0) {
// since read may NOT always read the whole buffer, we use
acutal_read to determine how much is read :
actual_read = myInternet_DataInputStream.read(buffer, n,
buffer_size - n);
n += actual_read;
if (actual_read > 0)
total_length += actual_read;
else
EOF_flag = true;
}
// calculate and display the speed
// some debug message...
myfile_BufferedOutputStream.write(buffer, 0, total_length);
}
My question is, why the programs running on Internet is much slower than
expected. When I put on the debug message, I found that it always stop
for a while when executing statements:
myInternet_DataOutputStream.write(buffer, 0, buffer_size); or
actual_read = myInternet_DataInputStream.read(buffer, n, buffer_size
- n);
I understand that read/write is blocking I/O, but the upload speed is
much lower than 27k to 59k. Is there any tricks to solve the program?
Another question is, how large should be the buffer size? I have tried
256 byte to 65536 byte, but not much difference.
Thanks in advance
Nelson
I am using Java DataInputStram and DataOutputStream to send a large file
thorugh Internet. When I test it with local LAN, the speed is fairly
fast and acceptable. With the same testing PCs and programs, I send the
file through Intenet, using ADSL boardband modem. I found that the speed
is as low as 15k to 17k byte per second. The bottleneck seems to be the
uplink side.
I am using 1.5Mb (bits per second) ISP service. The actual uplink speed
when I am using some network monitor tools is 27k to 59k byte per second
on average. That means, my program is running too slow when transfering
data through Internet.
My upload program is :
while (myfile_BufferedInputStream.read(buffer, 0, buffer_size) != -1) {
myInternet_DataOutputStream.write(buffer, 0, buffer_size);
// calculate and display the speed
// some debug message...
}
My download program is :
while (!EOF_flag) {
int n, total_length, actual_read = 0;
while (n < buffer_size && actual_read >= 0) {
// since read may NOT always read the whole buffer, we use
acutal_read to determine how much is read :
actual_read = myInternet_DataInputStream.read(buffer, n,
buffer_size - n);
n += actual_read;
if (actual_read > 0)
total_length += actual_read;
else
EOF_flag = true;
}
// calculate and display the speed
// some debug message...
myfile_BufferedOutputStream.write(buffer, 0, total_length);
}
My question is, why the programs running on Internet is much slower than
expected. When I put on the debug message, I found that it always stop
for a while when executing statements:
myInternet_DataOutputStream.write(buffer, 0, buffer_size); or
actual_read = myInternet_DataInputStream.read(buffer, n, buffer_size
- n);
I understand that read/write is blocking I/O, but the upload speed is
much lower than 27k to 59k. Is there any tricks to solve the program?
Another question is, how large should be the buffer size? I have tried
256 byte to 65536 byte, but not much difference.
Thanks in advance
Nelson