Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

java socket speed

Posted on 2000-04-25
11
Medium Priority
?
866 Views
Last Modified: 2012-05-04
Are TCP/IP sockets, with client/server written in Java, slower than in other languages like C++ ?
If it is slower what things can be done to increase file transfer speeds?
0
Comment
Question by:magosse
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 7

Expert Comment

by:Sasha_Mapa
ID: 2749427
Using a BufferedReader/BufferedWriter will increase speed a LOT.
I'm sure they would be slower, but not much slower, because they are after all implemented in native code...
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 2749558
calling native code from Java is much slower that calling Java code from Java code (try Double.longBitsToDouble() for example ...)
0
 
LVL 3

Expert Comment

by:falter
ID: 2749588
But there is no way around the native code.
The only things you can do is avoid
DataOutput/InputStreams they will break down all calls to a single byte read or write which at least calls a native function read one byte ore write one byte to the socket.
So BufferedReader/Writer as Sasha_Mapa mentioned will be a good choice.

If this is not enough you can write your one SocketImpl with your one code or you
write only a replacement for net.dll (windows), libnet.so (Unix) ...
But this will not be a trivial task.
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2749602
Yes, buffering can make a BIG difference. According to performance material published in the "Client Server Programming with Java/Corba" book, the difference between writing to a socket using a DataOutputStream and writing to a socket using a BufferedOutputStream decorated by a DataOutputStream was two orders of magnitude.

The timings published for a simple ping application were 300.5ms per message when using just DataOutputStream and 2.1ms per message when using BufferedOutputStream in conjunction with DataOutputStream.

Choosing the right buffer size is important. The default constructor of BufferedOutputStream creates a 512-byte buffer. You will likely want to create a stream with a buffer large enough to contain some unit of the message that you want to send -- optimally the entire message. Remember too, to flush -- something every good mother teaches ;-)

Best regards,
Jim Cakalic
0
 
LVL 7

Expert Comment

by:Sasha_Mapa
ID: 2749887
heyhey, what I meant is that it can't be faster under any conditions because both use (the same?) native code... Thanks for the info though, didn't know it was much longer to call native code... So does that mean I should leave my implementation of antialiased Graphics in Java and not move it to C and call it from Java?
0
 
LVL 3

Expert Comment

by:falter
ID: 2749979
Depends on the number of calls you made to the native code.
Is it one method doing all the stuff and give you some result back, you will only recognize it if you will call this methods realy often.

Same effect as using Bufferd streams in socket programming, reducing the number of native calls, means reducing the overhead you got through a JNI call.
0
 
LVL 16

Accepted Solution

by:
heyhey_ earned 100 total points
ID: 2750215
so back to teh question:
>> Are TCP/IP sockets, with client/server written in Java, slower than in other languages like C++ ?

yes. and you don't have the ful SOCKET functionality (in Java you work on pretty high level)

>> If it is slower what things can be done to increase file transfer speeds?

not much. if you really need a good speed, why don't you use C++ (which is platform independent enough)

re calling native code: yes - the slowest part is 'calling' native code. if you can reduce this kind of traffic (JavaVM -> native code and back) your app will work much better (note that - after all - almost all the standard API at the end calls some platform / native code :)
0
 
LVL 7

Expert Comment

by:Sasha_Mapa
ID: 2751043
ignore my last comment... I wrote it at 5am in the morning :-)
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 2756085
hmm ... thanks :)
0
 
LVL 7

Expert Comment

by:Sasha_Mapa
ID: 2757390
silly users...
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 2758273
grade C ... will ruin my profile :)
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question