________________________________
> From: brave...@gmail.com
> Date: Sat, 24 Apr 2010 13:05:26 +0200
> To: itext-questions@lists.sourceforge.net
> Subject: Re: [iText-questions] performance follow up
>
>
>
> Hello,
>
> On Apr 23, 2010, at 10:50 PM, trumpetinc wrote:
> Don't know if it'll make any difference, but the way you are reading the file
> is horribly inefficient. If the code you wrote is part of your test times,
> you might want to re-try, but using this instead (I'm just tossing this
> together - there might be type-os):
>
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> byte[] buf = new byte[8092];
> int n;
> while ((n = is.read(buf))>= 0) {
> baos.write(buf, 0, n);
> }
> return baos.toByteArray();
>
> I tried your suggestion above and made no significative difference compared
> to doing the loading from iText. The fastest I could get my use case to work
> using this pre-loading concept was by loading the whole file in one shot
> using the code below.
If as indicated below you are generally IO limited, don't throw
the code out yet. If you must copy data you want to use array
based methods as often as possible but the first preference
is to avoid copies unless of course you are strategicly
preloading or something.
I often just turn everything into a byte array but
obviously this doesn't scale too well unless you are content to let
VM do your swapping for you. Ideally you would just load what you
need in a just-in-time fashion to avoid tying up idle RAM.
>
> Applying the cumulative patch plus preloading the whole PDF using the code
> below, my original test-case now performs 7.74% faster than before, roughly
> 22% away from competitor now ...
>
> btw the average response time numbers I was getting:
>
> - average response time of 77ms original unchanged test-case from the office
> multi-processor-multi-core workstation
> - average response time of 15ms original unchanged test-case from home using
> my MBP
>
> I attribute the huge difference between those two similar experiments mainly
> to having an SSD drive in my MBP ... the top Host spots reported from the
> profiler are related one way or another to IO so would be no wonder that with
> an SSD drive the response time improves by a factor of 5x. There are other
> differences though e.g. OS, JVM version.
>
Multi-proc and disk cache can cause some confusions. I wouldn't ignore
task manager for some initial investigations- if the CPU drops and disk
light comes on you are likely to be disk limited. With IO it is easy
to get nickel-and-dimed to death as everyone who relays the data
can be low on profile chart but it adds up. Wall-clock times are least
susceptible to manipulation and may be best for A-B comparisons
if you have control over other stuff running on machine ( cash flow versus
pro-forma earnings LOL). If you can subclass
the random access file thing you may be able to first collect statistics
and then write something that can see into the future a few milliseconds.
All the generic caches work on past results, things like MRU except maybe the
prefetch
which assumes you will continue to do sequential memory accesses. If you
are in a posittion to make forward looking statements that have a material
impact on your performance you ( ROFL) you may be able to
do much better.
> Best regards,
> Giovanni
>
> private static byte[] file2ByteArray(String filePath) throws Exception {
> InputStream input = null;
> try {
> File file = new File(filePath);
> input = new BufferedInputStream(new FileInputStream(filePath));
>
>
> byte[] buff = new byte[(int) file.length()];
> input.read(buff);
>
> return buff;
> }
> finally {
> if (input != null) {
> input.close();
> }
> }
> }
>
>
_________________________________________________________________
Hotmail is redefining busy with tools for the New Busy. Get more from your
inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_2
------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/