MySQL Connector / C ++ freezes when reading ()

I am writing a multithreaded application in C ++ using Boost threads (pthread). The application spawns 100 threads, and each thread performs the following task (I write a piece of code that will be launched in each thread):

try {

    driver = get_driver_instance();
    con = driver->connect(SettingsClass.HostName, \
                  SettingsClass.UserName,SettingsClass.Password);

    // SettingsClass is a global static class whose members 
    // (HostName, UserName, Password, etc) are initialized once
    // before *any* thread is created.

    con->setSchema("MyDatabase");

    driver->threadInit();

    string dbQuery = "select A, B, C from XYZTable where D=?";
    prepStmt = con->prepareStatement(dbQuery);
    prepStmt->setInt(1, 1);
    rSet = prepStmt->executeQuery();

    /* Do Something With rSet, the result set */

    delete rSet;
    delete prepStmt;
    if (con != NULL && !con->isClosed()) {
        con -> close();
    driver->threadEnd();
    delete con;
    } 
    catch (SQLException &e) 
    {
        /* Log Exception */                            
    }

When the process starts (the application, as mentioned earlier, i.e. with 100 such threads), I attach gdb halfway and observe that more than 40% of the threads hang in the read () call. All reverse traces have mysql library functions (vio_read (), etc.), and none of them are from my code, since my code does not perform any I / O.

Can anyone please indicate why this problem occurs. Should I check my code / network or MySQL configuration? Did I use the C ++ Connectors library correctly?

0

All Articles