Jun 11, 2005

How to use MySQL with named-pipe

When you link to MySQL, use a dot "." instead of localhost or IP at host name field.

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.

Jun 1, 2005

MySQL, mysqlclient.lib, Visual C++, Windows XP

It's really hard to find related information of compiling programs with MySQL static library mysqlclient.lib. Fortunately, I got it!
There are two ways to link MySQL library, use libmysql.dll and mysqlclient.lib.

Use libmysql.dll:
Files libmysql.lib and libmysql.dll are at c:\program files\mysql\mysql server 4.1\lib\opt.
Just add libmysql.lib to your project. libmysql.lib is only a wrapper of libmysql.dll. Therefore, your program must run with libmysql.dll. The run-time library can be single thread version (/ML) or multi thread version.

Use mysqlclient.lib:
mysqlclient.lib is at same dictionary above. Add mysqlclient.lib to your project. If you build your project and get a lot of linker errors (LNK2001), you need to add some lib files to your project. Make sure that your project links wsock32.dll, advapi32.dll, and mysqlclient.lib. Open the propertity page of your project, click Linker options, click "input", click "other dependency", add .lib files as you need. You have to use multi-thread run-time library(/MT). The command line looks like
/OUT:"Release/LGP.exe" /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\Program
Files\MySQL\MySQL Server 4.1\lib\opt" /DEBUG /PDB:"Release/LGP.pdb"
/SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG /MACHINE:X86 mysqlclient.lib wsock32.lib kernel32.lib
user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

If you open libmysql.dll at depends, the tool comes with Visual C++, you will see libmysql.dll depends on three DLLs: wsock32.dll, kernel32.dll, and advapi32.dll. That's why Mr. Armin Schoeffmann this web page:
http://www.issociate.de/board/post/182627/Linker_error_LNK2001_with_vc++6.0_and_mysqlclient.lib.html
suggests add advapi32.lib to LINK32_FLAGs. However, in my case, I lack of wsock32.lib not advapi32.lib.

If you are using Borland C++ Builder, you can use the utility IMPLIB to make your own libmysql.lib file, and use libmysql.dll to connect MySQL. Unfortunately, I don't know how to let BCB users use mysqlclient.lib.
If you have any question, please let me know.