MySQL Connector/C++ hangs on read()

别来无恙 提交于 2019-12-25 06:32:30

问题


I am writing a multi-threaded application in C++ using Boost threads (pthread). The application spawns 100 threads and each thread does the following task (I am writing a code snippet that will be running 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 */                            
    }

On running the process (the app, as earlier mentioned, i.e. with 100 such threads), I attach gdb midway and observe that more than 40% of the threads have hanged in the read() call. All the backtraces have mysql library functions (vio_read(), etc) and none are from my code as my code does not perform any I/O.

Could anyone point out why is this issue arising. Should I check my code / network or MySQL server configuration? Have I used the C++ connector library properly?

来源:https://stackoverflow.com/questions/14152209/mysql-connector-c-hangs-on-read

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!