About Performance Tuning in java

What good ways to improve performance of code that uses lot of strings?

Use appropriate data structures and algorithms.
[url http://java.sun.com/developer/technicalArticles/Interviews/devinsight_1/]Write dumb code.
Don't worry about microoptimizations, and don't look for "clever tricks."
Don't assume something will be "slow" and then write fugly code to "fix" it. Write clean, simple code using standard idioms, test it, and if it doesn't meet your performance requirements, profile it to find where the bottleneck is, and once you find and fix that, test and profile again to see if the fix actually made a significant improvement. If it didn't, and the new code is not at least as clean as the old, then revert it back to the previous code.
All of the above advice applies for all Java coding, not just String-heavy cases.
The only semi-major String-specific performance/memory techniques that come up are as follows. And they don't really matter all that often in the real world:
1. When building up a String in a loop, if the pieces are large or if there are many pieces, use StringBuilder or StringBuffer's append() method, not direct String concatenation with plus-equal.
// do this
String s;
StringBuilder sb = new StringBuilder();
while (...) {
  sb.append(something);
s = sb.toString();
// not this
String s = "";
while (...) {
  s += something;
  // or
  s = s + something;The reason for this is that with the second approach, every time through the loop we create a new String object and copy all the characters over from the previous one. The first approach just keeps adding characters to the end of the existing StringBuilder.
However, this really only makes a practical difference if the pieces are very large, or if there are a lot of them.
Also note that String s = "a" + b + "c" + d; is fine, because the compiler turns those into append() calls anyway.
2. Use new String() when taking a small substring of a large String, if the small one will be kept around much longer than the larger original.
// do this
String s1 = a_very_large_string;
String s2 = new String(s1.substring(5, 7));
// not this
String s1 = a_very_large_string;
String s2 = s1.substring(5, 7);The reason for this is that substring uses the same backing array as the original. If we're done using the large String, that String object itself may become eligible for GC, but the large backing array will be kept around as long as the smaller String is alive. In this case, we're wasting most of its space for just a few characters. However, when we do new String(), that creates a new String object with its own backing array of just the characters that are part of that String, so once the original goes away, its large backing array can go with it.
If the strings are of about the same scale, or if they're both small or even only "sort of large," this will not be an issue. Also, if both of the Strings' lifetimes end at about the same time, it won't be an issue.
Again, though, don't overdo it. Pay close attention to the cases I described where these techniques don't matter.
Edited by: jverd on Oct 6, 2010 10:08 PM
Edited by: jverd on Oct 6, 2010 10:10 PM
Edited by: jverd on Oct 6, 2010 10:21 PM

Similar Messages

  • Looking for book about performance tuning 11g database

    Hi,
    I am looking for books about performance tuning oracle 11g. The documents from OTN 2 days 11g performance tuning and performance tuning guide are not really study material.
    Has someone idea?
    greeting,
    Max

    Hi,
    http://astore.amazon.com/oraclebooks-20/detail/1590599683 {Part IV Database Tuning }
    Greetings,
    Sim

  • Query About performance tuning

    Hi Guru's
    May be this question is stupid one, but i think this is the forum where every user get details of all there questions.
    I want to start learning Performance tuning but not know the path from where to start can anyone suggest me the same.
    Thanks in advance

    Hi,
    performance tuning is a huge area. It involves following skills:
    1. Understanding how Oracle stores data (physical structure of tables and indexes) and how it reads and writes it.
    2. Understanding how Oracle processes and executes queries
    3. Ability to read execution plans (not just scan them for 'red flags')
    4. Familiarity is most common wait events, knowing and understanding Oracle Wait Interface and its limitations
    5. Ability to understand AWR and ASH data and its limitations
    6. Understanding Oracle optimizer and it's inputs, knowing basic formulas for cardinality and selectivity, cardinality feedback tuning
    7. Abilty to read trace files (first of all extended SQL trace, 10046, and CBO trace, 10053)
    8. Understanding concurrency and read consistency and work Oracle does to maintain them.
    This is probably not a complete list. Of course you won't be able to learn everything at once. You can start by reading:
    1. The official Oracle Performance Tuning Guide
    2. T. Kyte's books on Oracle architecture
    3. Milsap's and Holt's book "Optimizing Oracle Performance"
    4. J. Lewis "Cost based fundamentals"
    Best regards,
    Nikolay

  • KDE4 + wallpaper slideshow: few questions about performance / tuning.

    Hello,
    I am using KDE 4.4 from pacman and set my desktop activity to slideshow. I would like to customize few things and thus - I have few questions:
    1) Is it possible to change / disable transition effect when changing wallpapers? All my desktop is choppy and not responsive while the wallpaper changes and I am wondering if there is a way to repair this? (all images used as walls are at max 3MB big, usually something about 1MB. I have 7200 RPM disk, 2GB of ram and rather fast graphics card with newest Nvidia drivers, so I don't know what is the cause of slowdown...)
    2) How can I programatically progress wallpaper to next image (not with the right click / Next Wallpaper image)?
    3) Is there a way to disable the wallpaper change while there is a fullscreen application running? I am asking this, because when I watch HD movies and the wall changes, movie playback is really choppy... (I think that answer to the first question will also help me in this case).
    I would be glad for any sugestions / interest in helping me;)
    Best regards,
    Mike.

    Hello
    1/ There's no way I know to remove the transition. Using the "raster" graphics engine helps a lot on performance : kill plasma-desktop and launch  `plasma-desktop -graphicssystem raster`
    2/ There's a plasma applet for this :
    http://kde-look.org/content/show.php/Ne … tent=94251
    http://aur.archlinux.org/packages.php?O … twallpaper
    Maybe you can adapt it to your needs / find out how it works.
    Last edited by xvello (2010-05-16 16:20:24)

  • Report running for long time & performance tuning

    Hi All,
    (1). WebI report is running for long time.so what are the steps i need to check for it ?
    (2). Can you tell me about performance tuning in BO ?
    please help me.....
    Thanks
    Kumar

    (1). WebI report is running for long time.so what are the steps i need to check for it ?
    The first step is to see if the problem lies in the query on the data source or in webi itself. Depending on the data source there are different ways to extract the query and try to run it against the database. Which source does your report uses?
    (2). Can you tell me about performance tuning in BO ?
    I would recommend to start by reading the administrator's guide. There is a section about how to improve performance.
    Regards,
    Stratos

  • Need clear steps for doing performance tuning on SQL Server 2008 R2 (DB Engine, Reporting Services and Integration Services)

    We have to inverstigate about a reporting solution where things are getting slow (may be material, database design, network matters).
    I have red a lot in MSDN and some books about performance tuning on SQL Server 2008 R2 (or other) but frankly, I feel a little lost in all that stuff
    I'am looking for practical steps in order to do the tuning. Someone had like a recipe for that : a success story...
    My (brain storm) Methodology should follow these steps:
     Resource bottlenecks: CPU, memory, and I/O bottlenecks
     tempdb bottlenecks
     A slow-running user query : Missing indexes, statistics,...
     Use performance counters : there are many, can one give us the list of the most important
    how to do fine tuning about SQL Server configuration
    SSRS, SSIS configuration ? 
    And do the recommandations.
    Thanks
    "there is no Royal Road to Mathematics, in other words, that I have only a very small head and must live with it..."
    Edsger W. Dijkstra

    Hello,
    There is no clear defined step which can be categorized as step by step to performance tuning.Your first goal is to find out cause or drill down to factor causing slowness of SQL server it can be poorly written query ,missing indexes,outdated stats.RAM crunch
    CPU crunch so on and so forth.
    I generally refer to below doc for SQL server tuning
    http://technet.microsoft.com/en-us/library/dd672789(v=sql.100).aspx
    For SSIS tuning i refer below doc.
    http://technet.microsoft.com/library/Cc966529#ECAA
    http://msdn.microsoft.com/en-us/library/ms137622(v=sql.105).aspx
    When I face issue i generally look at wait stats ,wait stats give you idea about on what resource query was waiting.
    --By Jonathan KehayiasSELECT TOP 10
    wait_type ,
    max_wait_time_ms wait_time_ms ,
    signal_wait_time_ms ,
    wait_time_ms - signal_wait_time_ms AS resource_wait_time_ms ,
    100.0 * wait_time_ms / SUM(wait_time_ms) OVER ( )
    AS percent_total_waits ,
    100.0 * signal_wait_time_ms / SUM(signal_wait_time_ms) OVER ( )
    AS percent_total_signal_waits ,
    100.0 * ( wait_time_ms - signal_wait_time_ms )
    / SUM(wait_time_ms) OVER ( ) AS percent_total_resource_waits
    FROM sys.dm_os_wait_stats
    WHERE wait_time_ms > 0 -- remove zero wait_time
    AND wait_type NOT IN -- filter out additional irrelevant waits
    ( 'SLEEP_TASK', 'BROKER_TASK_STOP', 'BROKER_TO_FLUSH',
    'SQLTRACE_BUFFER_FLUSH','CLR_AUTO_EVENT', 'CLR_MANUAL_EVENT',
    'LAZYWRITER_SLEEP', 'SLEEP_SYSTEMTASK', 'SLEEP_BPOOL_FLUSH',
    'BROKER_EVENTHANDLER', 'XE_DISPATCHER_WAIT', 'FT_IFTSHC_MUTEX',
    'CHECKPOINT_QUEUE', 'FT_IFTS_SCHEDULER_IDLE_WAIT',
    'BROKER_TRANSMITTER', 'FT_IFTSHC_MUTEX', 'KSOURCE_WAKEUP',
    'LAZYWRITER_SLEEP', 'LOGMGR_QUEUE', 'ONDEMAND_TASK_QUEUE',
    'REQUEST_FOR_DEADLOCK_SEARCH', 'XE_TIMER_EVENT', 'BAD_PAGE_PROCESS',
    'DBMIRROR_EVENTS_QUEUE', 'BROKER_RECEIVE_WAITFOR',
    'PREEMPTIVE_OS_GETPROCADDRESS', 'PREEMPTIVE_OS_AUTHENTICATIONOPS',
    'WAITFOR', 'DISPATCHER_QUEUE_SEMAPHORE', 'XE_DISPATCHER_JOIN',
    'RESOURCE_QUEUE' )
    ORDER BY wait_time_ms DESC
    use below link to analyze wait stats
    http://www.sqlskills.com/blogs/paul/wait-statistics-or-please-tell-me-where-it-hurts/
    HTH
    PS: for reporting services you can post in SSRS forum
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • Performance tuning SELECTs:  Can I force a TRUE db read every time?

    Good day everyone!
    I've been programming in ABAP for almost 6 years now, and I'd like to begin learning more about performance tuning with respect to database performance.
    More specifically, I'm testing some things in a particular SELECT in a report program we have that is timing out in the foreground because of the SELECT.  When I first run the program, the SELECT goes against the database, as we all know.  Subsequent runs, however, use the buffered data, so the response is a lot quicker and doesn't really reflect that first, initial database read.
    Am I correct in assuming that I should be testing my various approaches and collecting performance runtimes against that initial, "true" database read?  If that's the case, is there any way I can force the system to actually read the database instead of the buffered data?  For those experienced with this kind of performance analysis and tuning, what's the best approach for someone very new to this area such as myself?
    Thank you,
    Dave

    Hi Dave and Rob,
    Just my two cents (and yes, I know this is already answered, but..).
    I think you might be confusing 2 things: one is SAP buffering, and another one is caching at other levels (database, operating system, etc).
    From what I understood Rob was talking mainly about SAP buffering. In that context it is true that if there is a first execution that loads the buffers (for example, some not so small fully buffered tables) then that is an atypical execution, and should be discarded. In real life you will never have execution times like those, except maybe on the very first execution on a monday morning.
    Another thing is database caching. If you execute a report twice with exactly the same parameters then you might not be actually making physical reads in the second execution. This second execution will be very fast, but that will not be simulating real life: no user wants a report to be fast the second time you execute it with exactly the same parameters.
    To avoid this in Oracle you can empty the so-called SGA, but that is not so useful and it will probably not get you closer to what happens in the real life.
    So what to do? In doubt, measure it several times, with different parameters, and probably exclude the extreme values.
    Regards,
    Rui Dantas

  • Performance tuning of a function which is part of a package.

    Hello
    I just built a function in a package. And now I want to make sure that the SQL is well tuned.
    I was going through the links mentioned in this post
    Performance Tuning
    to know more about performance tuning.
    But I am confused with some simple things.
    So when we analyze a single function present in a package , should I use the SQL of the function or
    should I use a call to that function.
    For example first I thought of using EXPLAIN PLAN.
    I see a different explain plan when I use a call to that function then
    when I use the actual SQL of the function with some plugged in parameters whereever required.
    What is the right way of doing it?
    Thank you

    I recommend :
    1. use SQL tracing with DBMS_MONITOR and then TKPROF on raw SQL trace file
    2. call the function as it used in your production environment
    See good examples in http://www.oracle-base.com/articles/10g/SQLTrace10046TrcsessAndTkprof10g.php (just refer to DBMS_MONITOR examples and TKPROF).
    Note that SQL trace will only trace SQL and not PL/SQL. If SQL elapsed time does not match function call elapsed time close enough, you need to use DBMS_PROFILER to know where PL/SQL non SQL code elapsed time is used.
    I don't recommend using EXPLAIN PLAN because it has known limitations http://docs.oracle.com/cd/E11882_01/server.112/e16638/ex_plan.htm#PFGRF94673 (others have said "EXPLAIN PLAN lies" - you can google for this expression ....).
    Edited by: P. Forstmann on 10 févr. 2012 19:44

  • Can Anybody Send Me The Latest Testking Pdf Of  1z0-033 (Performance Tuning

    Hello,
    Can Anybody Send Me The Latest Testking Pdf Of 1z0-033 (Performance Tuning
    my email address is asiforacle [email protected]
    Regards,
    Asif Iqbal
    Software Engineer. ( Karachi, Pakistan ).

    The answer is surely NO but what I would like to ask for the sake of curiosity , why did you ask about Performance Tuning questions over Sql /Plsql forum , not on Database General Forum? Not that you should go there now and ask, just curious.
    Tell you what, read the free book(yup free). Here it is,
    http://download.oracle.com/docs/cd/B10501_01/server.920/a96533.pdf
    You won't need anything else to read, not even that testking stuff too.
    HTH
    Aman....

  • BDB Performance Tuning.

    Hello All,
    In efforts to tune BDB JE's performance, I'd like to ask everyone what sort of things you have looked at and tried. The application looks like this: it has multi-threaded reads/writes with large number of small entries. One thread for writing and another for reading. Most the performance tuning is needed on writing to the database, preferably to support stable insertion/modification times. Each entry is no more than 4KB (keys and entries are constant size)
    Some research indicates that changing page size to be equal to the size of the entry is helpful. I've looked at this: http://www.oracle.com/technology/documentation/berkeley-db/db/gsg/JAVA/dbconfig.html#pagesize
    However, DatabaseConfig.setPageSize() is nowhere to be found. Am I missing something? Where can I access this setting?
    I've also been having problems with database grinding to a near halt with large amounts of entries (under 1 mil) and total database file size of about 800MB. What are the general suggestions/practices for speeding things up? In this case performance is preferred over memory use.
    Thank you,
    Mike.

    Hi Mike,
    Some research indicates that changing page size to be
    equal to the size of the entry is helpful. I've
    looked at this:
    http://www.oracle.com/technology/documentation/berkele
    y-db/db/gsg/JAVA/dbconfig.html#pagesize
    However, DatabaseConfig.setPageSize() is nowhere to
    be found. Am I missing something? Where can I access
    this setting?You're looking at the docs for the wrong product -- that's the C product. The JE docs are here:
    http://www.oracle.com/technology/documentation/berkeley-db/je
    (Note the je suffix as opposed to the db suffix, which is the C product.)
    I've also been having problems with database grinding
    to a near halt with large amounts of entries (under 1
    mil) and total database file size of about 800MB.
    What are the general suggestions/practices for
    speeding things up? In this case performance is
    preferred over memory use.Have you tried increasing the JE cache size (EnvironmentConfig.setCacheSize)? In general, databases perform better with more memory. But to do performance tuning the first step is to normally print out the EnvironmentStats periodically and correlate changes in the stats with the performance you're seeing. Please see the performance section of the JE FAQ:
    http://www.oracle.com/technology/products/berkeley-db/faq/je_faq.html
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Improve Portal performance with BI-Java by adding additional server node.

    Hi SAP Expert
    I wonder anyone might have attempted this before,
    In an environment with BI-Java and Portal Java stack installed on the same server, is it possible to improve the system performance by adding additional portal server node? or is there any improvement seen by adding the extra server node?
    I am after suggestion and experience on how the portal performance can be improve, with consideration of BI-Java sharing Portal resources.
    Any comment will be most appreciated.

    Hi Jim,
    We've this configuration at our site, Portal and BI running together (not federated).  Recommendations would be to:
    1. Set a sensibly large max heap size on each server node of Portal (at least 2GB if not larger) and implement several nodes at least.  For example we have 4 x physical nodes, each running 3 server nodes of 2GB max heap size apiece so a total of 12 nodes.
    2. Implement the BI Safety Belt for large results sets (1127156)
    3. Implement the latest JVM / JDK you can on your environment.  We found much improved performance after implementing JDK SR10 with the J9/2.3 options enabled e.g.,  -Xjvm:j9vm23
    -Xsoftrefthreshold0
    4. Patch your BI components on the Portal (BIBASES, BIWEBAPP etc) to the latest available patch level for your Portal SP level
    5. Make sure all your RFC connections are load balanced to the backend and tuned for the kind of load you expect on your reports, and the BI is sized appropriately in terms of app servers and dialog work processes, RFC-enabled login groups in SMLG etc.
    6. Consult notes 1048691 (especially useful, opions &PROFILING=X&TRACE=X added to reports for example for performance tracing), 937697, 1021921, 948158 for information about problem analysis for this scenario
    7. Implement SAP Web Dispatcher for Portal to reduce load on static mime files
    8. Tune the Portal application.  There's plenty information on SDN related to Portal performance tuning.
    I hope this helps!
    Cheers,
    Marc

  • IFS performance tuning

    I have oracle 9iFS setting on a windows box. It works well initially, after I batch loaded about 100,000 documents into it. It becomes quite slow. Open a folder through SMB client takes tens of seconds. Does anyone have some performance tuning tips? Or anyone has similiar situation with large amount of documents?
    Thanks

    I have oracle 9iFS setting on a windows box. It works well initially, after I batch loaded about 100,000 documents into it.It becomes quite slow. Open a folder through SMB client takes tens of seconds. Does anyone have some performance tuning tips?
    Or anyone has similiar situation with large amount of documents?
    Thanks If running analyze doesn't help the problem, please post a new thread, and we'll try to help you. When you do, please answer these questions:
    - How many documents per folder?
    - Can you detect whether your iFS Java processes or your Oracle processes are the bottleneck?
    + If the bottleneck is an 9iFS Java process, then go into the Enterprise Manager tool (configured with iFS), and bring up the Node Performance Dialog (see page 2-25 of the 9iFS Setup and Administration Guide).
    + For your server, bring up the information described in Figure 2-20 of the 9iFS Setup and Admin Guide. "Service Details: Committed Data Cache".
    - Adjust these settings higher and see if your performance improves.
    Alan

  • Performance tuning of BPEL processes in SOA Suite 11g

    Hi,
      We are working with a customer for performance tuning of SOA Suite 11g, one of the areas is to tune the BPEL processes. I am new to this and started out with stress testing Hello World process using SOAPUI tool. I would like help with the below topics -
    1. How do I interpret the statistics collected during stress testing? Do we have any benchmark set that can indicate that the performance is ok.
    2. Do we need to run stress tests for every BPEL process deployed?
    2. Is there any performance tuning strategy documentation available? Or can anybody share his/her experiences to guide me?
    Thanks in advance!
    Sritama

    1. How do I interpret the statistics collected during stress testing? Do we have any benchmark set that can indicate that the performance is ok.
    You need
    pay attention to:
    java heap usage vs java heap capacity
    java eden usage vs java eden capacity
    JDBC pool initial connections vs JDBC pool capacity connections
    if you are using linux: top
    if you are using aix: topas
    2. Do we need to run stress tests for every BPEL process deployed?
    yes, you need test each BPEL. You can use "Jmeter" tool.
    Download Jmeter from here: Apache JMeter - Apache JMeter™
    Other tools:
    jstat
    jstack
    jps -v
    Enterprise Manager
    WebLogic Console
    VisualVM
    JRockit Mission Control
    3. Is there any performance tuning strategy documentation available? Or can anybody share his/her experiences to guide me?
    I recommend "Oracle SOA Suite 11g Performance Tuning Cookbook" http://www.amazon.com/Oracle-Suite-Performance-Tuning-Cookbook/dp/1849688842/ref=sr_1_1?ie=UTF8&qid=1378482031&sr=8-1&keywords=oracle+soa+suite+11g+performance+tuning+cookbook

  • Performance tuning in CRM server

    Hi everyone,
       My CRM server working very slow. Idont know the exact reason. My server configuration IBM Xeon processor 3 Ghz 3GB RAM.There are about 25 users. Is this problem with SAP or Hardware.If any one have performance tuning document plz post it.
    Thanks,
    Murali

    Chech the following:-
    Processor usage
    Ram usage
    background jobs
    how many user at a time
    what kind of job they do
    Any Network Problem
    Increse Work Processor
    increase Virtual Ram
    And for 25 users, You need System with 2 CPU and 4 Gb Ram
    Regards

  • Performance tuning in XI, (SAP Note 857530 )

    Could any one pls tell me where to find sap notes.
    I am looking for "SAP Note 857530 "
    Integration process performance(in sap XI).
    or how can I view the performance of the integration process ? or exactly how performance tuning is done.
    pls help,
    Best regards,
    verma.

    Hi,
    SAP Note:
    Symptom
    Performance bottlenecks when executing integration processes.
    Other terms
    ccBPM
    BPE
    Performance
    Integration Processes
    Solution
    This note refers to all notes that are concerned with improving the performance of the ccBPM runtime.
    This note will be continually updated as improvements are made.
    Also read the document "Checklist: Making Correct Use of Integration Processes" in the SAP Library documentation, on SAP Service Marketplace, and in SDN; it contains information about performance issues to bear in mind when you model integration processes.
    Refer to the appended notes and maintain the default code changes by using SNOTE, or by importing the relevant service packs. Note that some performance improvements cannot be implemented by using SNOTE and are instead only available in service packs.
    Regards
    vijaya

Maybe you are looking for

  • Mass activity scheduling

    Hi experts, I’m facing some problems to deal with mass activity jobs. When I run some mass activity transaction (ebw_dw_ss for instance) I get many records, but when I create a job to run this transaction, it doesn’t work; the job always ends with 0

  • Oracle 8i SQL and PL/SQL plus

    hi everybody, i am trying from two weeks to install oracle 8i SQL and PL/SQL plus on my PC on both Windows 2000 & XP and I installed every java runtime environment I found "the old and the new" but the SETUP insists on not working though it worked on

  • Tecra 8000 - hard drive connection

    Hi, My old Tecra 8000 gave up last night after 4 years' faithful service. It's simply refusing to start booting most of the time. I think it's a motherboard problem as it occasionally boots from floppy and remains stable for about 10 minutes. I know

  • Login troubles

    well installation went fine and i fallowed all instructions. Come time to login i used the name i gave durning installation which as far as i know just asked for a host name, no real user name. and the password i had to type in twice. At login it fai

  • Pass bean property name across JSP pages

    First, the sample code: <%-- ================ some.jsp =============== --%> <%-- bunch of code [...] --%> <tr> <td><bean:message key="prompt.desc" /></td> <td><html:textarea property="desc" /></td> </tr> <tr> <td> <bean:message key="prompt.notes" />