jueves, 30 de agosto de 2007

Optimization

Once upon a time I applied to a job in a big consultancy shop here in Santiago.

They were requiring a J2EE expert. After several interviews it was like 23:00 pm at night. 8-O

I was having this interview with a technical manager and he was asking me ow to optimize J2EE applications. Do you know how to optimize the application?

He explained that they built a huge application and that it neede to do something like 2 transactions per second and they were unable to do so. Do you have any ideas on how to optimize this?

First, I find it very uncharming to ask questions liek this. I mean, of course I can answer that, but you will have to pay the big bucks BEFORE I tell you how to.

So, what would you have replied in that case?

I remembered other projects I saw failing at other companies in which people struggled for months in order to write the code.

Then they struggled for months in order to compile the code.

I wish you are thinking the same as I'm thinking: These dudes had no idea what they were doing. They should have compiled before doing any check-in, but of course they didn't even know CVS or SVN even existed.

The good thing about having people like this in the market is that there is a lot of job offers (in the economic sense: a lot of people looking for jobs) and therefore the market price goes down, but on the other hand all these failed projects make the market price go up. Letting them fail is like a charm for asking for a raise.

Probably now you think I'm totally wrong on this, but it is a market, and if there is no lack of the product or service, it is impossible to make a profit. And failed project taint the company, not the individual workers, who go job hoping and therefore can't be blamed for anything.

Even the most knowledgeable hiring manager wouldn't know about every project in a city, and since today with globalization most projects are subcontinent-wide, it really is impossible to know the outcome of every project.

So failure and success is irrelevant. At least for individual workers.

But most projects fail not because people does not have the skills, but they don't know how to apply the skills and even more important, when to apply those skills.

In Search Of Stupidity

People are stupid, yeah, sometimes. Mostly all the time. That's why interfaces are defined to be fool proof.

People can't concentrate on the big picture if they are solving the small picture all the time, so you need to solve all those irrelevant details, as if people were stupid.

When you do that, people feel more confortable because they can concentrate on the big picture.

Unless the learnt Unix and vi, in which case they think they are smarter because they know all those arcane details. But Unix and specially vi people will go the way of the VAX system. They are completely negiglible.

The people we should care about are the people who understand that the best interface is the one that doesn't need a manual. Unix people are so smart that you can even type "man man" and the computer shows a manual on the "man" command. Useless, or course, but complete.

Or completely useless.

Optimization

Optimization has several techiniques that have been known for decades. It is a sign that "the inmates are running the assylum" that you get interviewed on how to optimize. It is the same as being hired for solving an equation.

What? Are you kidding me?

But some people lack basic instruction, and at least here in Chile, the number of people studying at the universities is going to double by 2012.

This means that if now I consider that it is very hard to hire acceptable engineers, it will get next to impossible by 2012.

The first problem this people have is that they are told to optimize from the very beggining. I don't understand the rationale, but I certainly remember from calculus that you can't optimize both locally and globally at different places the same function. You simply get impossible solutions.

You either optimize locally or you optimize globally. And of course it is better to optimize globally, beause that way you find the global optimum, instead of the local optimum, which is always somewhat worse than the global optimum.

Techniques

The techniques are:

1. Caches.
2. Buffers.
3. Copy on write.
4. Dirty bit.
5. Change number.
6. lock free/ wait free / non blocking algorithms.
7. cache oblivious algorithms.
8. read write locks
9. optimize at the end
10. measure, optimize, measure again.

The most important thing is to optimize at the end.
And then not to optimize unless you know for sure (you measured) that the response time is too slow.
And you make sure the code is clear, and the automated tests are run and they pass.
And there is not repeated code.
And then you still find that it is too slow.
Then you optimize the library, and make sure the library is not broken by running the tests.
If the optimization is not at least 5 times better, remove it and add a better one.

No hay comentarios: