Skip to content

Optimize: If failed on migrateToCurrentThread, put the server session back to global server session pool.#2467

Merged
oknet merged 1 commit intoapache:masterfrom
oknet:i2467
Oct 13, 2017
Merged

Optimize: If failed on migrateToCurrentThread, put the server session back to global server session pool.#2467
oknet merged 1 commit intoapache:masterfrom
oknet:i2467

Conversation

@oknet
Copy link
Copy Markdown
Member

@oknet oknet commented Sep 1, 2017

To be rebased after PR #2440 merged.

If global server session pool is enabled,

  • one server session is acquired
  • then try to migrate it to current EThread
  • if the migration failed, the server session will be closed.

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.

@oknet oknet added the HTTP label Sep 1, 2017
@oknet oknet added this to the 8.0.0 milestone Sep 1, 2017
@oknet oknet self-assigned this Sep 1, 2017
@zwoop zwoop requested a review from shinrich September 1, 2017 19:04
@SolidWallOfCode
Copy link
Copy Markdown
Member

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?

@oknet
Copy link
Copy Markdown
Member Author

oknet commented Sep 2, 2017

@SolidWallOfCode

This PR try to move the netvc first and then migrate it if it is not moved for now.

The move has better performance than migrate.

@zwoop
Copy link
Copy Markdown
Contributor

zwoop commented Sep 6, 2017

Just as the CI, I can't get this to build either :-).

gmake[2]: Entering directory '/usr/local/src/trafficserver/iocore/net'
  CXX      UnixNetVConnection.o
In file included from /usr/local/src/trafficserver/iocore/eventsystem/I_Continuation.h:41:0,
                 from /usr/local/src/trafficserver/iocore/eventsystem/I_Action.h:30,
                 from /usr/local/src/trafficserver/iocore/eventsystem/I_EventSystem.h:31,
                 from /usr/local/src/trafficserver/iocore/eventsystem/P_EventSystem.h:36,
                 from P_Net.h:94,
                 from UnixNetVConnection.cc:24:
UnixNetVConnection.cc: In member function ‘UnixNetVConnection* UnixNetVConnection::migrateToCurrentThread(Continuation*, EThread*)’:
/usr/local/src/trafficserver/iocore/eventsystem/I_Lock.h:72:97: error: no matching function for call to ‘MutexTryLock::MutexTryLock(SourceLocation, char*, NetHandler*&, EThread*&)’
 #define MUTEX_TRY_LOCK(_l, _m, _t) MutexTryLock _l(MakeSourceLocation(), (char *)nullptr, _m, _t)
                                                                                                 ^
UnixNetVConnection.cc:1447:3: note: in expansion of macro ‘MUTEX_TRY_LOCK’
   MUTEX_TRY_LOCK(lock_src, this->nh, t);
   ^~~~~~~~~~~~~~
In file included from /usr/local/src/trafficserver/iocore/eventsystem/I_Continuation.h:41:0,
                 from /usr/local/src/trafficserver/iocore/eventsystem/I_Action.h:30,
                 from /usr/local/src/trafficserver/iocore/eventsystem/I_EventSystem.h:31,
                 from /usr/local/src/trafficserver/iocore/eventsystem/P_EventSystem.h:36,
                 from P_Net.h:94,
                 from UnixNetVConnection.cc:24:
/usr/local/src/trafficserver/iocore/eventsystem/I_Lock.h:576:3: note: candidate: MutexTryLock::MutexTryLock(const SourceLocation&, const char*, Ptr<ProxyMutex>&, EThread*, int)
   MutexTryLock(
   ^~~~~~~~~~~~
/usr/local/src/trafficserver/iocore/eventsystem/I_Lock.h:576:3: note:   candidate expects 5 arguments, 4 provided
/usr/local/src/trafficserver/iocore/eventsystem/I_Lock.h:562:3: note: candidate: MutexTryLock::MutexTryLock(const SourceLocation&, const char*, ProxyMutex*, EThread*, int)
   MutexTryLock(
   ^~~~~~~~~~~~
/usr/local/src/trafficserver/iocore/eventsystem/I_Lock.h:562:3: note:   candidate expects 5 arguments, 4 provided
/usr/local/src/trafficserver/iocore/eventsystem/I_Lock.h:548:3: note: candidate: MutexTryLock::MutexTryLock(const SourceLocation&, const char*, Ptr<ProxyMutex>&, EThread*)
   MutexTryLock(
   ^~~~~~~~~~~~
/usr/local/src/trafficserver/iocore/eventsystem/I_Lock.h:548:3: note:   no known conversion for argument 3 from ‘NetHandler*’ to ‘Ptr<ProxyMutex>&’
/usr/local/src/trafficserver/iocore/eventsystem/I_Lock.h:534:3: note: candidate: MutexTryLock::MutexTryLock(const SourceLocation&, const char*, ProxyMutex*, EThread*)
   MutexTryLock(
   ^~~~~~~~~~~~
/usr/local/src/trafficserver/iocore/eventsystem/I_Lock.h:534:3: note:   no known conversion for argument 3 from ‘NetHandler*’ to ‘ProxyMutex*’
/usr/local/src/trafficserver/iocore/eventsystem/I_Lock.h:527:7: note: candidate: MutexTryLock::MutexTryLock(const MutexTryLock&)
 class MutexTryLock
       ^~~~~~~~~~~~
/usr/local/src/trafficserver/iocore/eventsystem/I_Lock.h:527:7: note:   candidate expects 1 argument, 4 provided
UnixNetVConnection.cc:1452:15: error: ‘class NetHandler’ has no member named ‘stopIO’
     this->nh->stopIO(this);
               ^~~~~~
UnixNetVConnection.cc:1454:5: error: ‘vc’ was not declared in this scope
     vc->thread = t;
     ^~
UnixNetVConnection.cc:1455:16: error: ‘class NetHandler’ has no member named ‘startIO’
     client_nh->startIO(this);
                ^~~~~~~
At global scope:
cc1plus: warning: unrecognized command line option ‘-Wno-format-truncation’
Makefile:1000: recipe for target 'UnixNetVConnection.o' failed
gmake[2]: *** [UnixNetVConnection.o] Error 1
gmake[2]: Leaving directory '/usr/local/src/trafficserver/iocore/net'
Makefile:596: recipe for target 'all-recursive' failed
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory '/usr/local/src/trafficserver/iocore'
Makefile:829: recipe for target 'all-recursive' failed
gmake: *** [all-recursive] Error 1

@oknet
Copy link
Copy Markdown
Member Author

oknet commented Sep 7, 2017

@zwoop This will be rebased after #2440 merged.

@oknet oknet force-pushed the i2467 branch 3 times, most recently from 3ad8dfd to 2d6142f Compare September 9, 2017 05:31
shinrich
shinrich previously approved these changes Sep 12, 2017
Copy link
Copy Markdown
Member

@shinrich shinrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this con_in.move was added to ensure the socket get's cleaned up?

Copy link
Copy Markdown
Member Author

@oknet oknet Sep 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

scw00
scw00 previously approved these changes Sep 14, 2017
Copy link
Copy Markdown
Member

@scw00 scw00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 looks good to me !

@oknet
Copy link
Copy Markdown
Member Author

oknet commented Sep 15, 2017

I will rebase this by PR #2501 later.

scw00
scw00 previously approved these changes Sep 15, 2017
Copy link
Copy Markdown
Member

@scw00 scw00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

// 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();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable.

@oknet
Copy link
Copy Markdown
Member Author

oknet commented Sep 19, 2017

ping @shinrich @scw00

Copy link
Copy Markdown
Member

@shinrich shinrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@oknet oknet merged commit c776c66 into apache:master Oct 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants