How to access MySQL from multiple threads concurrently

后端 未结 4 1765
悲哀的现实
悲哀的现实 2020-12-02 10:25

We\'re doing a small benchmark of MySQL where we want to see how it performs for our data.

Part of that test is to see how it works when multiple concurrent threads

4条回答
  •  一整个雨季
    2020-12-02 10:59

    Seems clear to me from the mySQL Docs that any specific MYSQL structure can be used in a thread without difficulty - using the same MYSQL structure in different threads simultaneously is clearly going to give you extremely unpredictable results as state is stored within the MYSQL connection.

    Thus either create a connection per thread or used a pool of connections as suggested above and protect access to that pool (i.e. reserving or releasing a connection) using some kind of Mutex.

提交回复
热议问题