Software Developer and Performance Engineer
Performance
Software Performance
Stop calculating dates for your queries in MySQL
Dec 29th
Recently I was working on a couple reports that were running slow. I was looking for indexes that could be created or modified in order to speed them up and provide a quicker response on my SellersToolbox.com website. I was able to find a couple but then the issue of dates popup up. I provide monthly, quarterly, and yearly reports and trying to select the right dates is very important. I have some logic there that determines the right range to be put into my queries.
What I learned recently though is that using functions such as YEAR(), MONTH(), and DAY() defeat the use of indexes and primary keys most of the time. Because these functions have to be performed on the date value, each record in the table is usually processed. This slows the query down greatly and causes a lot of needless computation to result.
What I found was the BETWEEN option in MySQL. Using this allows the query optimizer to utilize indexes fully, and eliminates the need for many date computations which can be expensive.
An added benefit I found was how to handle the beginning and end dates for my queries. Instead of calculating what the end date was, I could use the INTERVAL term and let MySQL figure it out for me. This also allowed me to use the same query for my monthly, quarterly, and yearly time ranges very simply. All I had to do was take the date and the interval such as the 3 examples below.
BETWEEN '2011-10-01' AND '2011-10-01' + INTERVAL 1 MONTH
BETWEEN '2011-10-01' AND '2011-10-01' + INTERVAL 3 MONTH
BETWEEN '2011-10-01' AND '2011-10-01' + INTERVAL 1 YEAR
In this way I didn't have to do any extra work in my application, and I was assured that MySQL would choose records in the correct date range and take advantage of my indexes and primary keys. In this case, trying to do some performance improvements taught me a better way to write my SQL and resulted in less code which was easier to understand.
As you can see, modifying the query with the right amount of time is quite trivial. I have dropdown values in the SELECT on my web pages and all I have to do is append "-01" and then append the interval the user has chosen. Its great when code can be made simpler and more powerful at the same time.
Java 7 Delayed again. Considering Scala…
Sep 8th
Well, it looks like JDK 7 is going to be delivered sometime in 2011 and JDK 8 will be in 2012. I’m all for smaller releases and shorter time between them. The only way to get adoption of new technologies is to get them out into the hands of developers and see how it plays out. The community wants a release so bad they are ready to take anything at this point. It has been 5 years since the release of JDK 6 and while it is a very good release, there are many things promised that would improve the platform and give it life again.
Waiting another 2 years to get features that are in Scala today seems like a waste of time. Sure, there are many developers who can wait since they are still working on projects with JDK 4 or 5. These shops will be ready for the new features when they are good and ready. The rest of us want the new JDK now though, and it looks like the wait is going to be even longer.
I have not looked at Scala before now, but I’m going to. My development work is still in JDK 6 for the Android platform. I don’t see that changing in the near future, but as far as languages go, Scala seems to have the mind power behind it to make it. The other languages I have looked at such as Groovy, JRuby, et. al. are nice, but it appears that momentum is behind Scala and so that is where I’m going to be focusing my learning. I just hope that JDK 7 comes out sooner than later.
How Many Performance Metrics is Enough?
Sep 3rd
I have been asked this question many times and for me it boils down to one idea.
You can never have too much of a good thing!
Running tests usually takes a lot of time and effort. There is planning, setup, executing the test, capturing data, and then processing that data. Having to rerun a test just to get some data that wasn’t captured before is a lot of work. That is why capturing everything up front can save a lot of time and aggravation.
A word of caution though. Watch the disk space while capturing. Make sure the drive won’t be filled with performance data. That could cause the test to fail and cause you to start all over again. Worse, parts of the system could become corrupted and require a complete reinstall and setup of the test.
So what do I monitor? Everything!
When using typeperf, nmon, JMX, database metric snapshots, or anything else; I try to capture much more than I need, but not so much so that I am capturing every piece of data possible. With typeperf, you can literally collect over 2000 different metrics. When pulling data from metric collection of a database, there can be hundreds of data points. Metrics about table spaces, buffer pools, resources, even down to the individual query.
Later I’ll discuss how I process this huge amount of data.
Week in Review – 29 August 2009
Aug 30th
Announcements
- Sun Java 6 Update 18 Released
Sun has released an update to the Early Release Program with the following changes:
- HotSpot version 16
- Support for Ubuntu 8.04 LTS
- JavaFX performance improvements
- Java WebStart related improvements for Java Store requirements
- List of deployment features:
Info
- Lessons learned from getting .NET to REST with Java Performance …
By Andreas Grabner
On a recent project I had to call Java REST services from a .NET Client. Several problems came up – ranging from authentication to hidden performance issues. I want to share my lessons learned and encourage you to share your own …