1 / 32

Optimize Your Java Code By Tools

Optimize Your Java Code By Tools. NuPoint Technology Inc. Manager of R&D Dept. Lin, Weicheng. Agenda. Why to Optimize Your Code? Introduction Optimize by OptimizeIt Conclusions. Why to Optimize Your Code?. Why coding?

davis-king
Télécharger la présentation

Optimize Your Java Code By Tools

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Optimize Your Java Code By Tools NuPoint Technology Inc. Manager of R&D Dept. Lin, Weicheng

  2. Agenda • Why to Optimize Your Code? • Introduction • Optimize by OptimizeIt • Conclusions

  3. Why to Optimize Your Code? • Why coding? • Why do your program need more execution time or developing time than that of others’? • Do you agree that Programming is an ART?

  4. Introduction • How to write a good program? • Suitable language • C++, Java, Perl, Scheme, … • Good algorithm • You need to learn Algorithm, OS, … • Good implementation • You need not only a good brain but a good tool • Bad implementation • Allocate too much memory • Instantiate too many objects • Bad programmatic logic • …

  5. Introduction (Cont.) • There are several tools for optimization use: OptimizeIt, … • Functions of Optimization Tools • Profiling • Code Coverage Checking • Thread Debugging • Progress Tracking • Request Analyzing

  6. Optimize by OptimizeIt • The goal of the optimization • A quick introduction to the application • Application architecture • Integrating JBuilder and OptimizeIt • Optimizing your first project

  7. The Goal of the Optimization • Using JBuilder and OptimizeIt to solve performance problems with an email agent • A user with 4000 Messages per day • Before the performance tuning • Several minutes • After the performance tuning • < 10 seconds • Improvement • Less execution time • Less required memory

  8. A Quick Introduction to the Application • Spam filtering It deletes spam from a user's mailbox using a variety of spam-filtering rules • Forwarding of desirable email messages to a pager A user can control which email messages should be forwarded from their inbox to their pager • Mail server-independence The Email Agent works with any email server that supports the POP-3 or IMAP standards • Platform-independence The Email Agent can run on any computer platform that supports Java, making it very flexible to install

  9. Application Scenario • Scenario • Currently, only a user, with 4,000 messages • About 1,000 spam messages • Running every five minutes • In the need of handling more users

  10. Application Architecture

  11. Basic Algorithm of the Email Agent • Application startup. • Initialize logger. • Read mail server connection properties. • Read properties for sending a summary report to the user. • Initialize internal lists from configuration files. • Create and populate the EmailAgent. • Connect to the mailbox. • Remove spam from the current folder. • Get the message list from the inbox. • Determine the UIDs of these messages. • Get a list of messages that have already been examined already. • While only looking at new messages: • One at a time, review each message to determine whether or not it is spam. • If the message matches an ``allow'' file rule, let it pass through. • Otherwise, test the From, Reply-To, and Subject fields, as well as message attachments. • If a message matches a notification criteria, send a message to my pager. • Close the mailbox and store. • Send me summary information about what actions were taken. Be care of your for-loop!

  12. Basic Configuration • Configuring the application • allow.from • allow.subject • allow.contents • reject.from • reject.subject • reject.contents

  13. Integrating JBuilder and OptimizeIt • Installation

  14. Integrating JBuilder and OptimizeIt (Cont.)

  15. Optimizing Your First Project

  16. Finding the Performance Problems Java Performance Tuning'' by Jack Shirazi • Measure the performance of the application, using tools, and/or by instrumenting the code. • Identify the location of any bottlenecks. • Think of a hypothesis for the cause of the bottleneck. • Consider any factors that might refute your hypothesis. • Create a test to isolate the factor identified by the hypothesis. • Test the hypothesis. • Alter the application to reduce the bottleneck. • Test that the alteration improves the performance. • Repeat from step 1.

  17. Finding the Performance Problems (Cont.) • Simplified version of the process • Instrument your code and find the major bottlenecks, using the best tools available • Fix the bottlenecks that are causing the biggest problems, don't worry about the others. If you can't fix it, avoid it • If performance is now acceptable, celebrate. If not, repeat from step 1

  18. Finding the Performance Problems (Cont.) • Fix the bottlenecks that are causing the biggest problems and don't worry about the others • Simplified analysis example • examineContents() - 70% • extractContents() - 20% • parseAttachment() - 10%

  19. The First Run: An Example of How to Use Avoidance Therapy

  20. Drill Down Your Programmatic Flow Using Contents needs a lot of time • Put this line in the last • It will be run when needed

  21. The Second Run Built in JDK 

  22. The Third Run: Problems with Regular Expressions aMatcher.find() wastes too much time indexOf is faster Change the order!

  23. aMatcher.find() is still slow, we use aMatcher.matches() 9,956 ms

  24. 9,548 ms

  25. Getting Harder Now 9,548 ms

  26. Getting Harder Now (Cont.) 9,353 ms

  27. Conclusions • Reducing the application runtime from over 52 seconds down to about 9.4 seconds • You really need a optimization tool, don’t you? • Now, do you agree that Programming is an ART?

  28. Thanks!

More Related