Java watermarking write slow

I am writing a Java Application to provide a digitally watermarked on-the-fly solution for a high voulme product......here are a few details of my logs after deployment(all times are in milliseconds) and each set conforms to a completed request,
Set 1.
INFO - ImageSource.setImage(51) | Time taken:121
INFO - WatermarkEngine.doWatermarking(48) | Time taken:29
INFO - ImageSource.writeStream(62) | Time taken write:775
INFO - CarsalesAction.carsales(52) | Time taken:949
Set 2.
INFO - ImageSource.setImage(51) | Time taken:113
INFO - WatermarkEngine.doWatermarking(48) | Time taken:15
INFO - ImageSource.writeStream(62) | Time taken write:964
INFO - CarsalesAction.carsales(52) | Time taken:1118
Set 3.
INFO - ImageSource.setImage(51) | Time taken:133
INFO - WatermarkEngine.doWatermarking(48) | Time taken:15
INFO - ImageSource.writeStream(62) | Time taken write:800
INFO - CarsalesAction.carsales(52) | Time taken:972
As is obvious the bottleneck to performace is the Image write to the servletouputstream which is handled by the ImageIO class from the 2D library. For testing, I started writing files by reading them as streams from the file-system and found that the write performance increases manifold by using code similar to,
InputStream inFile = new FileInputStream(context.getFile().getAbsolutePath());
InputStream in = new BufferedInputStream(inFile);
while (true) {
int data = in.read();
if (data == -1) {
break;
os.write(data);
Clearly when the input stream is buffered while reading from disk, the performance is good. However I am dealing with a BufferedImage(an in-memory object) and a standard library ImageIO for write.....any tips on how this can be optimised would be most welcome?
Thanks

are all your io-operations buffered?That is the question essentially.....
ImageIO.write(context.getRequestedImage(),"jpeg",os);where os is a BufferedOutputStream......is this the best way of handling the situation....if it is I find it hard to understnad why a write on an in-memory object should be slower than a write from the file-system as I mentioned in the original post??.

Similar Messages

  • Will java programs become slower with generics?

    This is not a question, more lika general discussion. I'd like to know what you think.
    I fear that the average java developer will become accustom to the new features of java and write inefficient code. I have included a sample program that shows new code vs. old code. Altough the new code is esier to read, it's also alot slower.
    For instance the foreach instruction is using an iterator which is created and then iterated. When the loop exits the Iterator is garanage collected. Better performance would be achieved if there was a "Getable" interface of some sort was implemented and that the foreach simply asked the collections class for the next object in line. Perhapps if the ArrayList cached it's Iterator objects, somehow. (I'm not suggesting any of the solutions above. I'm just trying to make a point.)
    Also regarding generics and enumerations it's easy to see how they will slow down the application. It gets even scarier when you consider that important foundation classes are updated with these new features. A small change in some AWT class may have unforeseen repercussions throughout all gui applications.
    Gafter, if you read this, is there any tests made to see if this is true. Is performance affected by the new features? Will old style code be replace by new style code in the foundation classes (awt/swing/.../... etc.).
    ArrayList<String> ss = new ArrayList<String>();
    for (int i = 0; i < 100; i++) ss.add("hello");
    // "new" java ... completes in 6.43 seconds
    long t1 = System.nanoTime();
    for (int i = 0; i < 1000000; i++)
         for (String s : ss)
    System.out.println(System.nanoTime()-t1);
    // "old" java ... completes in 2.58 seconds
    long t2 = System.nanoTime();
    for (int i = 0; i < 1000000; i++)
         for (int j = 0, size = ss.size(); j < size; j++)
              String s = ss.get(j);
    System.out.println(System.nanoTime()-t2);

    Adapting Neal's example for JDK 1.4:
        private static final String[] strArray = new String[0];   
        private static void withToArray() {
            List ss = new ArrayList();
            for (int i = 0; i < 100; i++) ss.add("hello");
            long t1 = System.currentTimeMillis();
            for (int i = 0; i < 1000000; i++)
                String[] ssArray =  (String[]) ss.toArray(strArray);
                for (int j=0;  j < ssArray.length; j++) {
                    String s = ssArray[j];               
            System.out.println(System.currentTimeMillis()-t1);
        private static final String[] strArray100 = new String[100];   
        private static void withToArrayAndCheatingOnLength() {
            List ss = new ArrayList();
            for (int i = 0; i < 100; i++) ss.add("hello");
            long t1 = System.currentTimeMillis();
            for (int i = 0; i < 1000000; i++)
                String[] ssArray =  (String[]) ss.toArray(strArray100);
                for (int j=0;  j < ssArray.length; j++) {
                    String s = ssArray[j];               
            System.out.println(System.currentTimeMillis()-t1);
        private static void withToArrayAndCheatingOnLengthLocalVar() {
            List ss = new ArrayList();
            for (int i = 0; i < 100; i++) ss.add("hello");
            final String[] localStrArray100 = new String[100];           
            long t1 = System.currentTimeMillis();
            for (int i = 0; i < 1000000; i++)
                String[] ssArray =  (String[]) ss.toArray(localStrArray100);
                for (int j=0;  j < ssArray.length; j++) {
                    String s = ssArray[j];               
            System.out.println(System.currentTimeMillis()-t1);
        } Allocating the string[] every time: 5812
    Allocating the correctly sized string[] once, as a private final static: 2953
    Allocating the correctly sized string[] once, as a final local var: 3141
    Interesting that the private final static is 90ms faster than the local variable, fairly consistently.
    What's interesting about that though, is that we're not iterating strArray100, we're iterating over ssArray, so its not clear why it should make a difference. If I modify things a little more:
        private static void withToArrayAndLoopOptimization() {
            List ss = new ArrayList();
            for (int i = 0; i < 100; i++) ss.add("hello");
            long t1 = System.currentTimeMillis();
            for (int i = 0; i < 1000000; i++)
                String[] ssArray =  (String[]) ss.toArray(strArray100);
                final int length = ssArray.length;              
                for (int j=0;  j < length; j++) {
                    String s = ssArray[j];               
            System.out.println(System.currentTimeMillis()-t1);
        private static void withToArrayAndLoopOptimizationLocalVar() {
            List ss = new ArrayList();
            for (int i = 0; i < 100; i++) ss.add("hello");
            final String[] localStrArray100 = new String[100];           
            long t1 = System.currentTimeMillis();
            for (int i = 0; i < 1000000; i++)
                String[] ssArray =  (String[]) ss.toArray(localStrArray100);
                final int length = ssArray.length;  
                for (int j=0;  j < length; j++) {
                    String s = ssArray[j];               
            System.out.println(System.currentTimeMillis()-t1);
        }  With private static final and loop optimization: 2937
    With local variable and loop optimization: 2922
    Now the different has disappeared: in fact, the numbers are exactly the same on many runs. You have to make 'length' final to get the best speed.
    I guess I'm disappointed that in 2004, Java 1.4 javac & Hotspot combined still cannot spot the simplest loop optimization in the book.... always assuming that's actually causing the preformance difference. My gut is telling me its something else causing the difference because all of the inner loops are iterating over ssArray, not strArray100 (wherever that happends to be declared).
    Someone care to run Neal's example on 1.5 and see if they've managed to optimize further under the covers?

  • Need a lot of custom JComponents, but Java just too 'slow', other Solution?

    Hi folks,
    first of all i'll try to explain my problem (although my english is quite bad)
    We're programming a tool for visualising graph algorithms (df search, strong connected components, transitive reduction etc.) For that, we got a drawing area (derived from JLayeredPane) which contains the Nodes and the Edges of a graph (for all that don't know what a graphs is, just imagine these nodes as numbered circles, and the edges as directed lines from one node to another).
    Both parts (Nodes and Edges) are derived from JComponent, because a) need MouseEvents on these Components and b) we need the ability to add them to a container (like JLayeredPane)
    An absolute requirement is that you can directly click on the edges (to mark them, or delete them etc)
    Another point which needs to be mentioned, the edges maintain a (invisible) polygon which lies around their line, this polygon is sensitive for mouseEvents.
    Now there are two main problems:
    * all these edges have (due to JComponent) (possibly) huge invisible rectangles (the only thing that really matters is the line from one corner of this rect. to the other) ...so if i got lets say a graph with 10.000 edges, there are a lot of edges that overlap (nearly 10.000 :) ) ... but only the Edge-object on top receives the MouseEvent (but perhaps the user wanted to cklick a edge that lies below the top-edge!) .. at the moment, the program looks at all edges below that which received the MouseEvent and checks wether the 'mouse'click' hits a polygon, If it does, the top edge dispatches the MouseEvent to that edge. (furthermore, due to the depth-order in a Layer of a JLayeredPane, we only need to look at all edges that are really below the egde that received the mouseEvent)
    This all works great for 'small' numbers of edges (approximately 1000-2000) but with a rising number of edges this attempt gets slower and slower (it takes 1-3 seconds to evaluate a single mouseclick on a Sun Ultra 5/333)
    * the bigger problem is, that if i got 10k+ JComponents in a Container Java gets really slow, just adding these 10k JComps. (to the JLayeredPane) takes some minutes?! Furthermore java consumes up to 200+ MB main memory in this situation.
    One solution we are currently thinking about is to implement these edges as 'pure graphics'-objects (for example the Container just draws all edges).. this probably solves problem # 2 but # 1 gets even worse (no depth-order, some more coordinates hassle)
    So, i hope someone can give me a hint for this problem or someone has had a similar problem before and has a good solution? (if the problem isnt clear, just ask)

    I worked on an application once that had a similar structure as yours, but we were only scaling up to about 1000-2000 components. The problem that we identified (and that you have, no doubt, also identified) is that you are searching all of the child components on every hit test/overlap test. What we did was to subdivide out outermost container so that it had a couple of dozen children, each of which then parented some of the original child components: this cut our search space for every hit test dramatically. We had the advantage of having collections of child componenents that we knew would not overlap so our first level containers did not overlap -- you may need your first level containers to overlap, but even with this, you'll still be able to much more quickly identify components in the immediate region that should be checked individuall.

  • My java is extremely slow in yosemite

    my java is extremely slow in Yosemite. i found existing comments on uninstall java and reinstall. I did reinstalled java couple of times, but not helping.
    when i simply enter java, java -version, javac in the terminal, its taking **** lot of time to respond. so not able to run even single simple java program. but other softwares are working fine. i am having python and running python code is pretty fast.
    how to resolve this?

    Apple doesn’t routinely monitor the discussions. These are mostly user to user discussions.
    Send Apple feedback. They won't answer, but at least will know there is a problem. If enough people send feedback, it may get the problem solved sooner.
    Feedback
    Or you can use your Apple ID to register with this site and go the Apple BugReporter. Supposedly you will get an answer if you submit feedback.
    Feedback via Apple Developer

  • Java is very slow on terminal servers

    Hi, we have several terminal servers for clients. But running Java (JRE) on a bank website, is very slow to load the Java plugin. So the whole login takes around 1-2mins to complete.
    We run Windows Server 2008 R2 which is virtualized with VMWare, we run the latest Java client v7 Update 17. Java has always been slow on these servers, is there a way to teak it somewho, so it loads faster?

    WoOber wrote:
    Its me who have setup the whole server, but users experience really that Java starts really slow when they try to login on their bank on the web.And how is that login done? In an applet? Because then the performance issue is on their own computer in their own private installations of browsers and Java runtimes, not your terminal. Applets tend to load 'slowly', especially on older versions of Java. The feeling of slowness tends to be because people compare the loading time to Flash, a completely different beast.

  • How to program in JAVA to write a file to CD

    Hi,
    How to write a program in JAVA to write a file in CD (Using CD-Writer)...

    Install packet-writing software and then write to the cd just like any drive.
    If you're using Windows XP, it has basic capabilities for this built in.
    http://support.microsoft.com/default.aspx?kbid=306524
    http://support.microsoft.com/default.aspx?kbid=279157

  • Why is Java startup so slow?

    Does anyone know why Java startup is so slow? Compared to other interpreted languages like Javascript and Perl, they run much faster. And can someone get technical with me? (But without pointing me to the JVM specification, which I don't understand.) It use to take longer for me to load Mozilla0.9 than a Java applet, but now Mozilla1.3 loads faster than a Java applet.

    "Connector" is a rather ill-defined way of describing
    it, which is why I chose the word -- to easily deflect
    further inquiries to quantify. ;>
    In a slightly more specific way, on start-up JVM needs
    to (not necessarily in order, 'cause I don't know the
    exact order) at the very minimum:
    1. Allocate memory.
    2. Query OS for a minimal set of needed facilities.
    3. Allocate memory. Allocate allocated memory
    (internally, for use by itself and the application).
    4. Map the OS facilities to Java facilities. (This is
    what I meant by "connectors").
    5. Allocate memory. Allocate allocated memory.
    6. Set up the internal control -- security managers,
    thread scheduler, gc, classloaders, calling stacks,
    virtual lookup tables, etcetc.
    Some of the above don't apply to applets.
    Thanks for the tip on 1.4.2beta. I'll give it a try. I
    assume you meant startup speed?All this is almost instant you realize. The real time it takes to start your program is that it takes much longer for Java classes to be loaded.
    The startup time is proportional to the number of classes you need to load to get your program running. If you only are writing a simple, console based java program the startup time will be much less then if you load a Swing application. Swing by itself is a huge number of classes, and then you have to load your classes. So it can take awhile.
    All the things you mention, every program has to do and the code that the JVM uses must be written in C or some other systems language.
    One reason at least on my machine that java startup is slow is that I have a slow hard drive. On my home machine, java is much faster around twice as fast to startup, but the processor and ram are not twice as good. I think that it's because the hard drive is faster. Because most of the time it's waiting for data from the disk and the Java enviroment has the disadvantage that it's very large on disk.

  • Java 2D very slow with Windows XP

    Hi all!
    I'm writing an isometric game engine using Java 2D API, in full-screen exclusive mode and using all the advantages of the new VolatileImage class. The engine is almost finished, I'm testing it putting some animated players on screen and showing the frame rate of the engine. Everything went right, frame rate was very high in Linux and Windows 98/Me. But when I try to run the engine on Windows XP I can only get 5 or 6 fps!!!! And I don't know why!! It seems that XP makes Java run very slow... at least when using Java2D...
    Please, anyone knows why the performance is reduced??? Is there a new JRE release for Windows XP?? I'm using JDK 1.4.1.
    Thanks for your help.

    If you're using the Fullscreen API, then you're using BufferStrategy, thus you shouldn't use VolatileImages, it does this for you in the background. You shouldn't create any buffers, simply use the one provided. I'm assuming your problem probably lies in transparency. I've made an isometric engine using the fullscreen API that has run with complete 60fps page flipping. I would assume your bottle-neck lies in:
    Transparencys (These are very slow, there is a way to make a bitmask, much like you'd do in DirectX)
    Dynamic Memory allocation/Alpha rendering in your animation loop. (You need to allocate ALL of the colors you're going to use, and avoid using an alpha component if you want to avoid the VM getting bogged down by the garbage collector because you're allocating 30 Color objects a second).
    I made a Color object that was some what hacked together that has methods to allow you to access it's values for doing this kind of thing, allocating your scheme before hand is an easier approach.
    The method that performs the page flipping is a BLOCKING method, so you should orient your drawing before it, and not assume it's simply placing a request, like repaint does.
    -Jason Thomas.

  • Can two java program write to the same port by fetching data from different

    can two java program write to the same port by fetching data from different ports, if yes is thing possible for a 3rd program to get all data (is there any data loss or collision)
    how is this possible

    can two java program write to the same port by fetching data from different portsTwo java clients can connect to the same server port and they can both write to it. However the server will see the connections as two separate accepted sockets.

  • Java Webservice client slow compared to dot net client

    we have DotNet webservice which is being called by two clients , one a dotnet client and other a javaclient
    The problem is java client is taking longer time in processing the results when compared to dotnet client and affecting the performance greatly , i'm using axis in java
    Is there any know issue with axis regarding my situation here.
    also the same java client when run on linux platform still longer time to process.
    please provide me some pointer here

    I would test the general performance difference between the 2 platforms on the same machine.
    I have the feeling that Java is generally slower on windows than .NET
    Microsoft has their secrets after all.

  • JCo writeHTML (java.io.Writer writer)

    Hello,
    I am using writeHTML(java.io.Writer writer) to dump something to a JSP page.
    However this call seems to close the "out" descriptor, which I think is programming with side effects and as such not correct. Has anyone experienced the same problem?
    kind regards,
    Frans.

    Hi Frans,
    I believe the writeHTML method is only intended for debugging purposes.
    However, you could use a StringWriter to buffer the results like this:
    StringWriter sw = new StringWriter();
    jco.writeHTML(sw);
    out.println(sw.toString());
    Hope this helps.
    Best regards,
    Daniel

  • Java serialization is slow in Solaris 10

    Hi,
    I'm think to migrate from Linux to Solaris 10, because of the better support for Java any many other things, but in the first test the java web application, we get a too slower response in Solaris, with a time of 03 minutes and 12 seconds for one transaction, but this same transaction using Linux on same hardware and database the transaction concludes in 4 seconds, I think that this maybe a misconfiguration on Solaris.
    In this application, all transaction are via JavaBean serialization over HTTP using an Applet that serializes/deserializes objects to a Servlet, seeing the tcp trace of http requests, after the server receives this requests, we get a pattern of 15 seconds to reply for every request.
    Then, maybe a mistake of TCP configuration in Solaris? or Java Applet Serialization to Servlet is slow in Solaris?
    Exists a best way to install Solaris for better performance with Java?
    Thanks for any help or ideas
    Cl�vis

    I obtained a T1000 on the 60 day try and buy with solaris 10. I've installed my java application on it. On start up the first thing the application does is de-serialize a huge java object.
    On my laptop (winXP single drive) this takes about 40 seconds.
    On the T1000 (single drive c0t0d0 <SUN80G cyl 65533 alt 2 hd 16 sec 149) it takes about 12 minutes. The application is identical.
    The java version on my laptop is 1.5.0_6
    The java version on my T1000 is 1.5.0_10
    I've doubled check to make sure the read and write cache is enabled on the disk.
    This is a major problem for me. Any ideas? The T1000 is doing nothing else. It is 100% idle before I start the java application.
    My application runs loads of threads and so I was hoping to get excellent performance which I haven't tested yet. However with a start up time of 12 minutes this is a no go straight away.
    I understand it is more to do with the disc and solaris 10, but can anyone explain to me why my laptop should be so much faster?>

  • PI 7.1 ESR and Java Webstart very slow

    Hi,
    I have been using the PI ESR and IB on the snow leapord OS with Mozilla and Safari browsers. The java webstart seems to be very slow  and working on the ESR objects is sometimes a pain as it takes long time to save , activate or change and sometimes I end up java heap space issues although we are running at a 2 gig heap size. Is it only me or is anyone else facing the same issue?
    Is it time to go back to good old windows XP? or can this be fixed in Mac ...I love my Mac for other reasons though...:)
    Teresa

    Hi,
    >>>serverXXXPI71
    add this server info with related IP address into your hosts file
    and it will work
    Regards,
    Michal Krawczyk

  • Using JSP / Java to write/create an xml file

    I have been looking around the internet and in my books and I cannot find a good example of JAVA/JSP writing an XML file. I already have a recursive method that will generate the xml .. what's missing in my code now is how am i goin to append or write that xml string into an existing file..
    suppose i have this xml string
    String xmlString = "<?xml version="1.0"?><txn><test>this is just a test</test></txn>";
    FileOutputStream fos = new FileOutPutStream(C://files/sample.xml);
    now , how i will write the xmlString into sample.xml file...
    Any suggestions/ ideas/ tutorial links would be deeply appreciated.. thx!

    never mind.. my code is workin now..

  • Java applet writes to file on client, no signing necessary

    Hi,
    I wonder if this is a feature or bug:
    I download and execute in my browser an unsigned applet/jar myCharts.jar from server. The applet references classes from package org.jfree.chart, which are not packed in myCharts.jar downloaded from server, but are locally stored on client in jre/lib/ext/jfreechart.jar (and therefore JVM running the applet loads and uses these local classes from local jar).
    The applet can write the file to client disk without any problem using classes from locally loaded jfreechart.jar. If I merge both jars into a big one and load it through network, file write access is forbidden.
    I am using JRE 1.5.0.3 for Windows and default java_policy file with 2      permissions added:
    permission java.lang.RuntimePermission "accessDeclaredMembers";
    permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
    Is it a bug, or feature ?
    According to my opinion these 2 permissions should not result in applet ability to write files using locally loaded classes.
    Thanks for your answer
    Martin

    The following is a duplicate posting in reponse to similar question:
    http://forum.java.sun.com/thread.jsp?forum=4&thread=200482&start=0&range=30#735223
    In short, you cannot write to a server without help from servier-side software such as a servlet, cgi, ASP, etc.
    If you go with something like an Oracle database on your server, it's a non-issue because the seucirty aspects are taken care of for you.
    V.V.

Maybe you are looking for

  • What is the best way to import photos from aperture to my new Lightroom

    What is the best way to import photos from aperture to my new Lightroom ?

  • Cant see my photos

    Not all the photos in my windows folders are appaearing in Elements 11 media view.  In one case only 1 photo appears in media view but 42 appear when I press "reveal in explorer" If I choose File|Get photos and videos I get the message "Nothing was i

  • P65+ RAW files with camera RAW - Not yet

    Folks, I'm just wondering if I'm alone here cos I can't find any mention anywhere online. Just had a shoot come in froma photographer (I'm in an ad' agency and we get all types of files from various photographers) shot on a P65+ back. The RAW TIFs ar

  • Report Painter: Possible to show Report with Zero (not No records were sel)

    Report Painter: Possible to show Report with Zero (not No records were selected) Dear Guru,   is there any way to make Report Painter to show Report with Zero / 0 when there were no record were found. (No records were selected). Regards, Howard

  • Error in posting Inbound IDOC

    Hi Gurus, I am trying to create Vendor by inbound IDOC by  enhancing the standard FM IDOC_INPUT_CREDITOR but IDOC is getting posted with status 51: Status 51: Trans. XK01 record 3 : Data record is not flagged as record type 2