[x265] Question about NUMA and core/thread use

Pradeep Ramachandran pradeep at multicorewareinc.com
Mon May 22 07:54:11 CEST 2017


On Thu, May 18, 2017 at 1:44 PM, Michael Lackner <
michael.lackner at unileoben.ac.at> wrote:

> Hello again,
>
> 1.) I have another question about x265s' NUMA support. After looking at
> the behavior of
> --pools and at the documentation, it became clear that x265 doesn't
> actually create
> individual thread pools for each NUMA node automatically.
>
> So on my 2-socket, 32-thread server, I just did it manually with
> '--pools="16,16"', and
> now it spawns two pools with 16 threads each instead of one pool with 32
> threads.
>
> Problem: The overall performance drops by ~15%, and when looking at the
> behavior, one of
> the two pools would often drop to 0-10% CPU usage for a few seconds, then
> start loading
> the CPU again, then drop again for several seconds, etc. It seems as if
> the second pool
> (and *only* the second pool, it doesn't happen for the first) needs to
> wait for something.
>
> This doesn't happen when spawning just one pool with 32 threads (x265s'
> default behavior).
> Load is near-maximum all the time, encode is faster.
>
> Other parallelization options, identical for all cases: '--wpp --pmode
> --pme --slices 4
> --lookahead-slices 4 --ctu 16 --max-tu-size 16 --qg-size 16'.
>
> Content is 8K again. Yeah, it works with '--pmode --pme' now, somehow,
> please don't ask me
> why, I have no idea..
>
> When searching the web I found this discussion, but it's pretty old:
>
> http://x265-devel.videolan.narkive.com/sbQflm3D/x265-cpu-uti
> lization-very-low-on-a-multi-numa-sockets-server
>
> They are talking about looking at 'DecideWait (ms)'. I've enabled frame
> stats with '--csv
> stats.txt --csv-log-level 2' to take look at potential issues.
>
> Ran:
> cat stats.txt | awk -F',' '{ print $33 "," $34 "," $36 "," $38 }' | sed
> 's/^\s//'
>
> This extracts all the "Wait" and "Stall Time" values, maybe this is
> relevant? I've
> attached the resulting files, one for a run with 2x16 NUMA thread pools
> and one for a run
> with just 1x32 thread pool spanning all CPUs across both nodes for a total
> of 117 frames.
>
>
> So actually using NUMA hurts performance? Should I not create thread pools
> for individual
> NUMA nodes after all? Or should I specify certain options to make this
> perform better than
> the flat topology/round-robin way of scheduling threads?
>
>
The 15% performance drop in linux when a single pool across sockets, as
opposed to a pool dedicated to each socket is created, is known. This is
why the default behavior of x265 in linux is to launch a single pool across
all sockets. If you want to use the --pools cli option to change this
behavior, you will see different performance. To launch 32 threads in one
pool across all sockets, you can say --pools 32 and it should work; this
will also be the default behavior on a 2-socket machine. If you give
--pools 16,16, you will get two pools, one per socket.

Unfortunately, on windows, there is no way to launch threads such that they
work across both sockets. Therefore, the default behavior on windows is to
launch a pool per socket. But I don't think this concerns your use case.


> 2.) Also, one more thing that's scaring me, the documentation for
> '--pools' says:
>
> "[...] In the case that the total number of threads is more than the
> maximum size that
> ATOMIC operations can handle (32 for 32-bit compiles, and 64 for 64-bit
> compiles),
> multiple thread pools may be spawned subject to the performance constraint
> described
> above. [...]"
>
> What does "may be spawned" mean? Like "the user may do this by specifying
> --pools" or
> "x265 may or may not do this for the user automatically"?!
>

There is a limitation that each pool can only handle up to 64 threads. (Bit
vector used to track the threads can only be 64-bit at max in a 64-bit
compile, and 32-bit at max in a 32-bit compile.). We therefore have some
heuristics to decide when to break into multiple pools even in linux based
on the total thread count of the machine and how far that number is from 64.


>
>
> Thanks for your time, and sorry if I'm asking something stupid! ;)
>

No such thing as a stupid question :-).


>
>
> On 05/10/2017 09:37 AM, Michael Lackner wrote:
> > On 05/10/2017 09:26 AM, Pradeep Ramachandran wrote:
> >> On Wed, May 10, 2017 at 12:32 PM, Michael Lackner <
> >> michael.lackner at unileoben.ac.at> wrote:
> >>
> >>> On 05/10/2017 08:24 AM, Pradeep Ramachandran wrote:
> >>>> On Wed, May 10, 2017 at 11:12 AM, Michael Lackner <
> >>>> michael.lackner at unileoben.ac.at> wrote:
> >>>>
> >>>>> Thank you very much for your input!
> >>>>>
> >>>>> Since --pmode and --pme seem to break NUMA support, I disabled them.
> I
> >>>>> simply cannot tell
> >>>>> users that they have to switch off NUMA in their UEFI firmware just
> for
> >>>>> this one
> >>>>> application. There may be a lot of situations where this is just not
> >>>>> doable.
> >>>>>
> >>>>> If there is a way to make --pmode --pme work together with x265s'
> NUMA
> >>>>> support, I'd use
> >>>>> it, but I don't know how?
> >>>>
> >>>> Could you please elaborate more here? It seems to work ok for us here.
> >>> I've
> >>>> tried on CentOS and Win Server 2017 dual socket systems and I see all
> >>>> sockets being used.
> >>>
> >>> It's like this: x265 does *say* it's using 32 threads in two NUMA
> pools.
> >>> That's just how
> >>> it should be. But it behaves very weirdly, almost never loading more
> than
> >>> two logical
> >>> cores. FPS are extremely low, so it's really slow.
> >>>
> >>> CPU load stays at 190-200%, sometimes briefly dropping to 140-150%,
> where
> >>> it should be in
> >>> the range of 2800-3200%. As soon as I remove --pmode --pme, the system
> is
> >>> being loaded
> >>> very well! It almost never drops below the 3000% (30 cores) mark then.
> >>>
> >>> I also works *with* --pmode --pme, but only if NUMA is disabled on the
> >>> firmware level,
> >>> showing only a classic, flat topology to the OS.
> >>>
> >>> That behavior can be seen on CentOS 7.3 Linux, having compiled x265
> 2.4+2
> >>> with GCC 4.8.5
> >>> and yasm 1.3.0. The machine is a HP ProLiant DL360 Gen9 machine with
> two
> >>> Intel Xeon
> >>> E5-2620 CPUs.
> >>>
> >>> Removing --pmode --pme was suggested by Mario *LigH* Rohkrämer earlier
> in
> >>> this thread.
> >>>
> >>
> >> This seems something specific with your configuration setup. I just
> tried
> >> an identical experiment on two systems that I have which are dual-socket
> >> E5-2699 v4s (88 threads spread across two sockets) running CentOS 6.8
> and
> >> CentOS 7.2. I compiled x265 with gcc version 4.4 and am able to see
> >> utilization actually pick up closer to 5000% (monitored using htop) when
> >> --pme and --pmode are enabled in the command line; without these
> options,
> >> the utilization is closer to 3300%.
> >
> > Hmm, crap. That would mean something's wrong with that HP server? But
> it's still very
> > strange. I've been able to reproduce this every time, even after a fresh
> reboot. Even if
> > it was a firmware bug, why would it trigger only when --pmode --pme are
> used...
> >
> > Maybe I should try a newer Linux kernel and not the stock one CentOS 7.3
> comes with?!
> >
> > Any way to debug this and see what's going wrong? I have no idea what to
> do...
> >
> >>> Here is my topology when NUMA is enabled (pretty simple):
> >>>
> >>> # numactl -H
> >>> available: 2 nodes (0-1)
> >>> node 0 cpus: 0 1 2 3 4 5 6 7 16 17 18 19 20 21 22 23
> >>> node 0 size: 32638 MB
> >>> node 0 free: 266 MB
> >>> node 1 cpus: 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31
> >>> node 1 size: 32768 MB
> >>> node 1 free: 82 MB
> >>> node distances:
> >>> node   0   1
> >>>   0:  10  21
> >>>   1:  21  10
> >>>
> >>> Thanks!
> >>>
> >>
> >> You seem to have very little free memory in each node which might be
> making
> >> you go to disk and therefore affecting performance. I recommend trying
> to
> >> free some memory up before running x265 to see if that helps.
> >
> > Nono, there was no swapping. It's just that the machine is currently in
> use transcoding 4K
> > stuff, so a some memory is actively allocated, and the rest is filled up
> with file
> > buffers, that's why numactl is showing this. See here:
> >
> > # free
> >               total        used        free      shared  buff/cache
>  available
> > Mem:       65672976     7371344     5737328       17544    52564304
> 57687116
> > Swap:      97224700           0    97224700
> >
> > For my test runs, I've even rebooted the machine and ran the test
> immediately afterwards.
> > There is nearly nothing on that machine, it's fresh. No servers, no X11,
> just the base
> > system with ffmpeg and x265 cli.
> >
> >>>>> Ah yes, I've also found that 8K does indeed help a ton. With 4K and
> >>>>> similar settings, I'm
> >>>>> able to load 16-25 CPUs currently, sometimes briefly 30. With 8K,
> load
> >>> is
> >>>>> much higher.
> >>>>>
> >>>>> Maybe you can advise how to maximize parallelization / loading as
> many
> >>>>> CPUs as possible
> >>>>> without breaking NUMA support on both Windows and Linux.
> >>>>>
> >>>>> I'm saying this, because my benchmarking project is targeting
> multiple
> >>>>> operating systems,
> >>>>> it currently works on:
> >>>>>   * Windows NT 5.2 & 6.0 (wo. NUMA)
> >>>>>   * Windows NT 6.1 - 10.0 (w. NUMA)
> >>>>>   * MacOS X (wo. NUMA)
> >>>>>   * Linux (w. and wo. NUMA)
> >>>>>   * FreeBSD, OpenBSD, NetBSD and DragonFly BSD UNIX (wo. NUMA)
> >>>>>   * Solaris (wo. NUMA)
> >>>>>   * Haiku OS (wo. NUMA)
> >>>>>
> >>>>> Thank you very much!
> >>>>>
> >>>>> Best,
> >>>>> Michael
> >>>>>
> >>>>> On 05/10/2017 07:21 AM, Pradeep Ramachandran wrote:
> >>>>>> Michael,
> >>>>>> Adding --lookahead-threads 2 statically allocated two threads for
> >>>>>> lookahead. Therefore, the worker threads launched to work on WPP
> will
> >>>>> 32-2
> >>>>>> = 30 in count. We've found some situations in which statically
> >>> allocating
> >>>>>> threads for lookahead was useful and therefore decided to expose it
> to
> >>>>> the
> >>>>>> user. Please see if this helps your use-case and enable
> appropriately.
> >>>>>>
> >>>>>> Now as far as scaling up for 8K goes, a single instance of x265
> scales
> >>> up
> >>>>>> well to 25-30 threads depending on the preset you're running in.
> We've
> >>>>>> found pmode and pme help performance considerably on some Broadwell
> >>>>> server
> >>>>>> systems but again, that is also dependent on content. I would
> encourage
> >>>>> you
> >>>>>> play with those settings and see if they help your use case. Beyond
> >>> these
> >>>>>> thread counts, one instance of x265 may not be beneficial for you.
> >>>>>>
> >>>>>> Pradeep.
> >>>>>>
> >>>>>> On Fri, May 5, 2017 at 3:26 PM, Michael Lackner <
> >>>>>> michael.lackner at unileoben.ac.at> wrote:
> >>>>>>
> >>>>>>> I found the reason for "why did x265 use 30 threads and not 32,
> when I
> >>>>>>> have 32 CPUs".
> >>>>>>>
> >>>>>>> Actually, it was (once again) my own fault. Thinking I know better
> >>> than
> >>>>>>> x265, I spawned
> >>>>>>> two lookahead threads starting with 32 logical CPUs
> >>>>> ('--lookahead-threads
> >>>>>>> 2').
> >>>>>>>
> >>>>>>> It seems what x265 does is to reserve two dedicated CPUs for this,
> but
> >>>>>>> then it couldn't
> >>>>>>> permanently saturate them.
> >>>>>>>
> >>>>>>> I still don't know when I should be starting with that stuff for 8K
> >>>>>>> content. 64 CPUs? 256
> >>>>>>> CPUs? Or should I leave everything to x265? My goal was to be able
> to
> >>>>>>> fully load as many
> >>>>>>> CPUs as possible in the future.
> >>>>>>>
> >>>>>>> In any case, the culprit was myself.
> >>>>>>>
> >>>>>>> On 05/04/2017 11:18 AM, Mario *LigH* Rohkrämer wrote:
> >>>>>>>> Am 04.05.2017, 10:58 Uhr, schrieb Michael Lackner <
> >>>>>>> michael.lackner at unileoben.ac.at>:
> >>>>>>>>
> >>>>>>>>> Still wondering why not 32, but ok.
> >>>>>>>>
> >>>>>>>> x265 will calculate how many threads it will really need to
> utilize
> >>> the
> >>>>>>> WPP and other
> >>>>>>>> parallelizable steps, in relation to the frame dimensions and the
> >>>>>>> complexity. It may not
> >>>>>>>> *need* more than 30 threads, would not have any task to give to
> two
> >>>>>>> more. Possibly.
> >>>>>>>> Developers know better...
> >>>>>>>
> >>>>>>> --
> >>>>>>> Michael Lackner
> >>>>>>> Lehrstuhl für Informationstechnologie (CiT)
> >>>>>>> Montanuniversität Leoben
> >>>>>>> Tel.: +43 (0)3842/402-1505 | Mail: michael.lackner at unileoben.ac.at
> >>>>>>> Fax.: +43 (0)3842/402-1502 | Web: http://institute.unileoben.ac.
> >>>>>>> at/infotech
> >>>>>>> _______________________________________________
> >>>>>>> x265-devel mailing list
> >>>>>>> x265-devel at videolan.org
> >>>>>>> https://mailman.videolan.org/listinfo/x265-devel
> >>>>>
> >>>>> --
> >>>>> Michael Lackner
> >>>>> Lehrstuhl für Informationstechnologie (CiT)
> >>>>> Montanuniversität Leoben
> >>>>> Tel.: +43 (0)3842/402-1505 | Mail: michael.lackner at unileoben.ac.at
> >>>>> Fax.: +43 (0)3842/402-1502 | Web: http://institute.unileoben.ac.
> >>>>> at/infotech
> >>>>> _______________________________________________
> >>>>> x265-devel mailing list
> >>>>> x265-devel at videolan.org
> >>>>> https://mailman.videolan.org/listinfo/x265-devel
> >>>>>
> >>>>>
> >>>>>
> >>>>> N �n�r����)em�h�yhiם�w^��
> >>>
> >>> --
> >>> Michael Lackner
> >>> Lehrstuhl für Informationstechnologie (CiT)
> >>> Montanuniversität Leoben
> >>> Tel.: +43 (0)3842/402-1505 | Mail: michael.lackner at unileoben.ac.at
> >>> Fax.: +43 (0)3842/402-1502 | Web: http://institute.unileoben.ac.
> >>> at/infotech
> >>> _______________________________________________
> >>> x265-devel mailing list
> >>> x265-devel at videolan.org
> >>> https://mailman.videolan.org/listinfo/x265-devel
> >>>
> >>>
> >>>
> >>> N �n�r����)em�h�yhiם�w^��
>
>
> --
> Michael Lackner
> Lehrstuhl für Informationstechnologie (CiT)
> Montanuniversität Leoben
> Tel.: +43 (0)3842/402-1505 | Mail: michael.lackner at unileoben.ac.at
> Fax.: +43 (0)3842/402-1502 | Web: http://institute.unileoben.ac.
> at/infotech
>
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20170522/a8639071/attachment-0001.html>


More information about the x265-devel mailing list