The Source for Java Technology Collaboration
User: Password:



Giovani Salvador's Blog

Giovani Salvador Giovani Salvador is one of the coordinators of the oldest JUG in Brazil, RSJUG, at the state of Rio Grande do Sul. He has worked as a university professor teaching Java and currently is a java architect at Dell in Porto Alegre, Brazil, where he is also doing his master's degree in computer science at Pontifical University Catholic. Giovani also owns SCJP and SCEA(I) as well as Certified Scrum Master (CSM).



Refactoring for Performance

Posted by giovanisalvador on April 28, 2008 at 07:36 AM | Permalink | Comments (3)

I was working on a kind of Outlook entirely based on the web and written 100% in Java. I was part of a team responsible for maintaining that application for thousands of users and performance was a critical piece. Actually, still is a critical piece because the application still exists and it is there for almost ten years.
I joined the team after the application has been released and being used for about 20,000. At that time, the team was not fully aware of helpful frameworks or design patterns that could help themselves to build a reliable, scalable software. Application was performing well but one of the parts of the application (a listing) was taking too long to process. Some users were complaining on that piece and I joined to help team specially on that part of the application.
First thing I decided to do was to put in place some tool to help us understand what was going on. At that time my IDE was Jbuilder Enterprise Edition and I had a license of Optimizeit. By plugging in it to the application I quickly noticed that building and access to lots of HashMaps instances were the culprit.
Then I had to understand the application's architecture:
The data layer was responsible for processing SQL statements sent to it, create HashMap instances for each record found and add each instance to a collection. Each column of the records found turned to a pair of column name and value.

The problem was that the application didn't have in place Transfer Objects or Value Objects. It was relying on maps and the application was facing performance problems on building those maps and suffering when accessing get methods of those maps, specially in those days where the load was so huge. That's what Optimizeit was telling me.

So I decided to make a small refactoring in my local environment after assessing the application with Optimizeit. I switched from maps to Transfer Objects in all layers of that piece of the application. Instead of making maps and collection of maps I created Transfer Objects and made them being accessed by the listing page. The Facade was responsible for returning the collection of Transfer Objects instead of a collection of maps.

When I ran Optimizeit again I noticed a gain of 20% in performance. After showing the results to the team we decided to release to production after some tests in Development Environment.
One day later I received a call from one of the users who originally complained about the performance:

- User: Hey, have you guys modified anything in the application?
- Why Sir?
- User: Because the listing is performing much better now.
- Actually, we did sir. We did a small modification on that piece.
- User: Alright, I will notify other users about that. Thanks for the work performed.

You guys may be surprised with this. Today, almost all applications rely on Transfer Objects, not on hashmaps. But at that time, with the knowledge of the former team, that's what was being used. The bottom line here is that small modifications may affect user experience. We don't need to make big refactorings to achieve that. Simple is better.
And you guys know the value of an user calling you to congratulate you. This is the most important piece.
Also, to put in place profiling tools like the one I had used is also key for the success of the project. You guys may be surprised with lots of things such tools may reveal about your code.

but I would like to know from you:
Has any of you some example on small refactorings that made the difference? Simple modifications that helped applications to improve performance. Please, share over here some real world facts about refactoring.




Java and the need for Dependency Injection

Posted by giovanisalvador on March 16, 2008 at 03:55 PM | Permalink | Comments (9)

I was talking to some of my team mates in Austin regarding the usage of Spring as opposed to "Heavy Weight Containers". They asked what I think about using Spring in the new features of an application they are working on. I have to admit that I never used Spring. Why? Because I never had to. All that I needed to do was supported by EJB Containers or the so called Heavy Weight Containers. Maybe I don't how happy I can be if I use Spring but so far services provived by Java EE containers were enough. And with clustering!!!

I also have to admit that previous versions of EJBs were almost untestable (It's horrible to have to mock an EJB) but at the same time put business logic into EJB (here I am talking about Session and Message-driven EJBs) is something that I don't like that much. I always used POJOs for business logic also to be more testable. My EJBs just acted as a facade to provide remotability. Anyway, when I asked to one of them what was the need he answered me: "I want productivity with Dependency Injection". And more, he told they were going to use Spring integrated with the EJB Container to take advantage of the existing services provided by the container. What? Hum, a self-called lightweight container integrated with a heavyweight container. This sounds interesting. He wanted to have the advantages of dependency injection but also taking advantage of the container's services.

So here I don't take any conclusion despite I have my own opinion on using one or antoher. I just would like to know everybody's opinion on this.

- How are you guys using Spring?
- Has someone already integrated Spring and Java EE container? To take advantage of what?
- And for those who are using only Spring, what are the pros and cons?
- Are you using only the framework or also Spring Portfolio?
I appreciate any comment on it. :)

April 2008
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      


Search this blog:
  

Categories
Community
Community: Java Enterprise
Community: Java User Groups
Performance
Archives

April 2008
March 2008
January 2008
December 2007

Recent Entries

Refactoring for Performance

Java and the need for Dependency Injection

Are we becoming Java Dinosaurs?



Powered by
Movable Type 3.01D


 Feed java.net RSS Feeds