Optimize: If failed on migrateToCurrentThread, put the server session back to global server session pool.#2467
Conversation
|
I'm not sure this is worth it. It's a lot of code to try to save a single outbound connection. Might it not be better to validate the VC can be moved first, rather than move it and then move it back? |
|
This PR try to move the netvc first and then migrate it if it is not moved for now. The |
|
Just as the CI, I can't get this to build either :-). |
3ad8dfd to
2d6142f
Compare
shinrich
left a comment
There was a problem hiding this comment.
Overall looks good to me. Once the dependent PR gets merged in.
|
|
||
| if (h->startIO(this) < 0) { | ||
| con_in.move(this->con); | ||
| Debug("iocore_net", "populate : Failed to add to epoll list"); |
There was a problem hiding this comment.
I assume this con_in.move was added to ensure the socket get's cleaned up?
There was a problem hiding this comment.
If startIO failed, move the con.fd back to con_in.fd. To avoid close the con_in.fd.
|
|
||
| // Try to get the mutex lock for NetHandler of this NetVC | ||
| MUTEX_TRY_LOCK(lock_src, this->nh->mutex, t); | ||
| if (lock_src.is_locked()) { |
There was a problem hiding this comment.
I like the move logic. If you can in fact get both locks, this is more efficient.
| } | ||
| if (new_vc->thread != ethread) { | ||
| // Failed to migrate, put it back to global session pool | ||
| m_g_pool->releaseSession(to_return); |
There was a problem hiding this comment.
I don't seeing doing the release buying us much, but it doesn't cost us much either. If the releaseSession doesn't get the lock, it will close the netvc anyway.
There was a problem hiding this comment.
The m_g_pool is locked at L312.
311 EThread *ethread = this_ethread();
312 ProxyMutex *pool_mutex = (TS_SERVER_SESSION_SHARING_POOL_THREAD == sm->t_state.http_config_param->server_session_sharing_poo l) ?
313 ethread->server_session_pool->mutex.get() :
314 m_g_pool->mutex.get();
315 MUTEX_TRY_LOCK(lock, pool_mutex, ethread);
316 if (lock.is_locked()) {
The to_return will be released to the pool.
|
I will rebase this by PR #2501 later. |
| // Since we moved the con context, the fd will not be closed | ||
| // Go ahead and remove the fd from the original thread's epoll structure, so it is not | ||
| // processed on two threads simultaneously | ||
| this->ep.stop(); |
There was a problem hiding this comment.
@shinrich @SolidWallOfCode Can we remove this?
The read.enabled and write.enabled set to 0 by do_io_close() that means the netvc is disabled.
It is not necessary to call ep.stop() here.
… back to global server session pool
To be rebased after PR #2440 merged.
If global server session pool is enabled,
The server session should be send back rather than do_io_close it.
The PR put the server session back to the global server session pool.