Jun 5, 2005

HyperThreading

Today I went to library and read magazines. Dr.Dobb is an excellent magazine for programmers. An article describes something about single CPU, hyperthreading, and dual core.

  • Singel CPU has one CPU Status, one Interrupt Controller, and one ALU.
  • HyperThreading CPU has two CPU status, two Interrupt Controller, and one
    ALU.
  • Dual core CPU has two CPU status, two Interrupt Controller, and two
    ALU.
This solves my question. I have a program which calls MySQL a lot of times to calculate function values. But when I used two threads, two connections of MySQL, that program isn't getting faster as I expect. I guess the reason is that hyperthreading CPU has only one ALU, while one MySQL connection executing function calculation, the other must wait until ALU becomes available. They are not parallel runing and look like

Time 1 -> Time 2 -> Time 3 -> Time 4
connection1
receive SQL -> perform SQL -> return results -> receive SQL
connection2
receive SQL -> idle -> perform SQL -> return results

To obtain benefit of multithreading function calculation, dual core CPU and multi-CPU are really ways to do that.

No comments: