On Fri, Apr 01, 2022 at 11:23:34AM +0200, Maciej Zdeb wrote:
> > I remember mentioning something about trying to change this in the future.
> > For outgoing connections I think we could try to figure where peers
> > connections are and always use one least represented thread.
> >
> If I understand the code correctly, the peer_session_create() function
> creates appctx by appctx_new() which allocates all outgoing connections on
> the current thread "appctx->t = task_new_here();"?
> So changing peer_session_create() into:
> 
> static struct appctx *peer_session_create(struct peers *peers, struct peer
> *peer, int thread) {
> ...
> appctx = appctx_new_on(&peer_applet, thread);
> if (!appctx)
>     goto out_close;
> ...
> }
> 
> where appctx_new_on() is a new function that creates an applet on a
> specified thread would fix my issue? I'm worrying it's not that easy and
> some locking here and there might be needed. ;-)

Indeed, I think it would work without problems! In this case you could
even add an array of MAXTHREADS to the peers struct to count the number
of applets per thread, then peer_session_create() could just scan the
threads to find the least loaded one and use this one. This would easily
do the job and sounds simple and efficient enough to get into 2.6.

Please, if you go that way, think about splitting your work in at least
3 patches:
  - 1 for appctx_new_on()
  - 1 to maintain the applet count per peers struct
  - 1 to use that counter to start the applet on the best thread

You may find that you need to implement more stuff, but you get the idea.

thanks,
Willy

Reply via email to