?
Solved

Faster bufferedInputStream, is it possible?

Posted on 1998-08-03
7
Medium Priority
?
363 Views
Last Modified: 2010-04-16
Hello.

I have a problem with bufferedinputstream, is there a way to speed it up.
So i can read faster from the bufferedinputstream?

Pierre Andersson
0
Comment
Question by:pierre_andersson
[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
  • 3
7 Comments
 
LVL 6

Expert Comment

by:gadio
ID: 1230724
What seems to be the problem with the bufferedinputstream's speed? Can you attach a code that shows the problem?
0
 

Author Comment

by:pierre_andersson
ID: 1230725
The problem is as follow:

I have a buffer with 200000 bytes and a bufferedinputstream connected to a server over a socket. When the server is sending really fast(1 String/ 1/2 second) the buffer(byte[200000]) is filled with strings and the time for the string to be shown in the client window is incresing.

Pierre Andersson.
0
 
LVL 6

Expert Comment

by:gadio
ID: 1230726
Pierre, could it be that you are displaying all the data in the buffer each time you display? That would explain the fact that the display time is increasing. Why don't you work with smaller buffers? It would be much more efficient.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:pierre_andersson
ID: 1230727
Thanks for your answer!!!

The problem is that i don't really know how big the buffer must be, because the server must serve 4000 clients and broadcast all the message to all the clients each time the server is receiving a message. I don't think that alla the clients will send a message at the same time but i want the server and client to be as fastest they can. Do you know what size the buffer should be.

Thanks for your help.

Pierre Andersson.
0
 
LVL 6

Accepted Solution

by:
gadio earned 200 total points
ID: 1230728
Pierre, when you read and write to sockets you are I/O bound, that is, the cpu is idle most of the time waiting for the communication to happen. I suggest that you try a different approach. If your messages are delimited by newline, try to use

// the input stream from the client socket is inpstr
BufferedReader br = BufferedReader(new InputStreamReader( inpstr ) );
while( /*condition*/ ) {
   String msg = br.readLine();
   if( /* msg is relevant to me */ ) {
      // Handle message
   }
}

If on the other hand, the message is delimited by some other characters, use the StreamTokenizer to break the stream to messages.

0
 

Author Comment

by:pierre_andersson
ID: 1230729
I am using $ to delimite the strings and StringTokenzier, is StringTokenizer ok, or should i use StreamTokenizer.

Pierre Andersson
0
 
LVL 6

Expert Comment

by:gadio
ID: 1230730
Use StreamTokenizer, mark all the characters that can be a part of a message as normal (including spaces), and the $ as whiteSpaceChars.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 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