New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MXS-1629:make threadid unique #160
Conversation
server/core/session.cc
Outdated
| @@ -49,7 +51,9 @@ using std::stringstream; | |||
| /** Global session id counter. Must be updated atomically. Value 0 is reserved for | |||
| * dummy/unused sessions. | |||
| */ | |||
| static uint64_t next_session_id = 1; | |||
| static uint32_t next_session_id = 1; | |||
| static SPINLOCK thread_id_lock = SPINLOCK_INIT; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change to session_id_lock
server/core/session.cc
Outdated
| static uint64_t next_session_id = 1; | ||
| static uint32_t next_session_id = 1; | ||
| static SPINLOCK thread_id_lock = SPINLOCK_INIT; | ||
| static std::tr1::unordered_set<uint32_t> threads = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change to session_ids
server/core/session.cc
Outdated
| spinlock_acquire(&thread_id_lock); | ||
| do | ||
| { | ||
| rval = atomic_add_uint32(&next_session_id, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is now protected by a lock, there's no need to use atomic_add_uint32 but you can simply increment next_session_id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit concerned about putting the session id allocation behind a lock (during which a memory allocation may be made), because experience has thought that these locks start to hurt when the load gets high. I may want to do this so that each worker thread has a session id pool of its own (reserved from a global session id pool), from which it allocates session ids, so that session id allocation in most cases can be made without any locking being involved.
|
I'd argue this change as well. I'm not that much into MaxScale code, but the reasoning of changing 64bit counter to 32bit counter with mutex and id registry is totally unclear to me. I'm not sure how often |
|
firstly, i will test this pr with following case, to measure how much impact with performance: secondly, if this pr be accepted, we want go further to impl global threadid since currently client session id is different from server session id, although we have a mapping in mxs, but it not work in a cluster deploy; our proposal is:
so if worker thread has a session id pool, another bits will be consumed @svoj mysql protocol constrained threadid to be 32bits, in mysql_client.cc:272 |
|
@svoj The session id is visible to the client as the thread id, which is only 32-bit. So, even if the former is 64-bit it'll still wrap as far as the client is concerned if the situation is as in https://jira.mariadb.org/browse/MXS-1629 |
|
Ok, that's a valid problem. Server uses 64bit |
|
@svoj The problem is that in the handshake package you only have 32 bits. |
|
I can imagine that the best solution would be either to extend handshake, or skip sending it to client, or skip using it in client for cases when uniqueness matters. If none of the above works, I'd still keep it 64bits and use |
|
svoj , this is about MySQL client-server protocol. And we have the same problem with overflow in MariaDB server, which we ignored so far. I.e we can send different clients the same 32bit session ids Client typically use that for KILL CONNECTION, i.e when we go over 32bit, KILL might fail, or clients would KILL wrong connecton |
|
@svoj : https://mariadb.com/kb/en/library/1-connecting-connecting/ , in the description of the packet, you can see int<4> connection id. Since the server cannot have more that 4 billions of connections at the same time, this connection id is not unreasonable. But changing protocol for that is not quite easy, since there are dozens of different native connectors for different languages. So connection ID should be 4 bytes, not 8, my opinion. |
|
@vaintroub Do you suffer from an overflow problem in the server, or do you reuse connection ids (that have been closed)? |
|
We suffer. MySQL does not suffer, since 5.7.5 https://mysqlserverteam.com/the-mysql-5-7-5-milestone-release-is-available/ (Proper Connection ID Handling, WL#7293) |
|
MySQL's solution is not efficient; thread_ids is an array |
|
I'll close this as we cannot have a global lock involved at each session id allocation. However, I've assigned MXS-1629 to myself and will provide a scalable solution. |
I am contributing the new code of the whole pull request, including one or
several files that are either new files or modified ones, under the BSD-new
license.