Java Development News:

Making a Real World PetStore

By Dion Almaer

01 Apr 2002 | TheServerSide.com

Introduction

The Java PetStore is an application from Sun's "Blueprints" group that is made to help educate people on various design patterns for the various parts of J2EE. The application focuses on showing as many patterns and parts of the framework in an application, and does NOT focus on performance.

In this article, we will discuss:

  • The history of PetStore
  • How can we make PetStore a real world application?


The History of PetStore

Although PetStore was not brought into the world to be used as a performance benchmark (that is what ECPerf is for), some companies have tried to use it for this very purpose. The first company to use PetStore in this way was Oracle. They made the claim Oracle runs Java applications in half the time as IBM or BEA. This brought many comments from the community, and of course feedback from the other vendors. BEA quickly came out with a press release claiming BEA WebLogic Server Outperforms IBM and Oracle on Their Own Performance Benchmarks. Obviously, these benchmarks can be tweaked and molded by each vendor, and it is hard to get an "apples to apples" test. Again, Sun would say ECPerf is for this purpose (but that gets us into another argument, for another time).

Before we know it, Microsoft steps to the plate with the Microsoft .NET PetShop. To go with this application is the comment Microsoft claims .NET version of Java PetStore is superior. The industry took this up with a number of articles like Pet vs Pet: MS opens .NET benchmarking wars.

If you check out some of the sites that I have mentioned, you will see a common theme:

  • PetStore isn't built for performance

What if we were to take the PetStore functionality, and wanted to tune it for the real world. What could we do?


Making PetStore for the Real World

As you look closely at how Microsoft created their PetShop, you can see some of the areas where they gain performance. The biggest factor is probably that they use stored procedures in SQL Server to do much of the work. This allows them to claim that the code base is smaller (since they put a lot in the DB), and also improves on the speed of data manipulation. We could change the J2EE PetStore to also use some stored procedures (via the BMP beans, or directly from the DAO's [Data Access Objects]). This would hurt our portability a little, since, although calling an SP is standard in JDBC, the procedure in the database would be different depending on the database (Oracle versus Sybase). Many databases do not even allow for stored procedures (MySQL).

To cater to all worlds, we could use a Strategy pattern that uses different methods depending on the type of database. We can have a base version that works on all databases, and then create specialized solutions for databases that support stored procedures. This will give us more "lines of code", and add some complexity, but this time, we are caring about performance! Does it make sense to go through all the JDBC code and make them all SPs? I don't think so. For all performance improvements, we need to get a base benchmark. From this we can optimize the areas that need it, as code normally follows the 80/20 rule (80% of the time is in 20% of the code). If we see a bottleneck in one area of data access, we can tweak that to use an SP.

If you look at the PetStore code you see it has many layers. We could flatten these layers (similar to de-normalizing a database, but in the application). The .NET PetShop doesn't even use COM+ (the equivalent of EJBs); it just goes from the web layer to the data layer using ASP.NET -> ADO.NET. We could strip out the EJBs from the PetStore if it helped on the performance side of things. If we didn't use an EJB layer, we wouldn't have a data caching framework (no CMP Entities). To get around this we could use JDO (now 1.0!).


Conclusion: We need your help

These are some obvious areas of PetStore that we could optimize. I am curious to get feedback from the J2EE Community on what YOU would do. In your projects, where have you gone in to tweak the performance? What tricks do you use? Have you thought about what you would change in the PetStore? Lets start up a thread on TheServerSide to talk about these issues!


 Resources

Oracle claims PetStore runs twice as fast on Oracle vs IBM, BEA:
/news/thread.tss?thread_id=10446

Oracle runs Java applications in half the time as IBM or BEA:
http://www.oracle.com/features/9i/index.html?9iasfast.html

BEA WebLogic Server Outperforms IBM and Oracle on Their Own Performance Benchmarks:
http://www.bea.com/press/releases/2001/0709_benchmark_bea-ibm-oracle.shtml

Microsoft claims.NET version of Java PetStore is superior:
/news/thread.tss?thread_id=9797

Microsoft .NET PetShop:
http://www.gotdotnet.com/team/compare/petshop.aspx

Pet vs Pet: MS opens .NET benchmarking wars:
http://www.theregister.co.uk/content/4/22781.html

Java Blueprints:
http://java.sun.com/blueprints/qanda/faq.html#code