Solved

java socket speed

Posted on 2000-04-25
11
858 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
  • 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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 50 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
hash value 2 39
topping3 challenge 14 52
Python Assistance 7 36
Java Jpanels and Jframe 8 20
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now