Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Performance Issue wth writing "text/javascript" content into HttpServletResponse  RSS feed

 
Samir Jyoti
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having performance problems with writing "text/javascript" content into the HTTPServletResponse using an OutputStreamWriter. It is taking 30 to 40 secs to write 1.1MB of dynamically generated javascript content (as String) into the OutputStream. I tried using the GZIPOutputStream but

a) The "write" operation performance has further dropped! by 20-30% and

b) The content reaching the browser is incomplete!

Any Suggestions?

Samir Jyoti
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a) This seems to suggest that it's not writing into the stream, but generating the content that's the bottleneck (compressing the content takes additional cpu time). Did you profile the problem?

b) Did you close the stream when you are finished?
 
Samir Jyoti
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a) Yes, I profiled it. The "write" operation is taking that much time after the javascript generation. So write is the issue.

b) Yeah I was not closing the Writer I created by

Writer writer = new OutputStreamWriter(response.getOutputStream(), "UTF-8");

But even after that no reduction in time although, a few 5-8 sec less yes, but not any more signficant amount.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So after closing the Writer, that did at least solve the problem of the incomlete output, correct?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Samir Jyoti:
a) Yes, I profiled it. The "write" operation is taking that much time after the javascript generation. So write is the issue.


Also if you don't compress the output?
 
Samir Jyoti
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:


Also if you don't compress the output?


I did the compression so that the "write" becomes faster.

The "close" operation solved the "in-complete" content problem but the performance problem while writing still persists. Here's what I am doing



the orignal problem code had:



the GZIP has further degraded the performance of write operation
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Samir Jyoti:

I did the compression so that the 'write' becomes faster....

...the GZIP has further degraded the performance of write operation


Compression is most helpful when the network is the bottleneck.
If you're not testing your app over a slow connection, you won't see much benefit from using it.
 
Samir Jyoti
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any other suggestions to make the "write" faster?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I guess you first need to find out *why* the write *is* slow in the first place.
 
Samir Jyoti
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:
Well, I guess you first need to find out *why* the write *is* slow in the first place.


yes that's what I am trying to figure out. I profiled the code, inside it

SocketOutputStream.socketWrite(byte[], int, int) is the costly method.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried buffering OutputStreamWriter?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Roger Chung-Wee:
Have you tried buffering OutputStreamWriter?


I'm not sure, but I'd rather buffer the stream than the writer...
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, buffering the OutputStream looks more promising. Am I correct in believing that buffering the writer makes a lot of sense for unbuffered streams, but may not be that useful for buffered streams.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SocketOutputStream.socketWrite(byte[], int, int) is the costly method.

If the application is spending a lot of time in that method, this suggests that it is being called way too often and that a BufferedOutputStream constructed on the ServletOutputStream will be a big help.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!