我的C ++应用程序在docker容器中运行速度较慢

问题描述 投票:0回答:1

我正在测试和分析我的一个应用程序,该应用程序作为docker容器运行。在测试期间,我注意到该应用程序在直接在我的主机中执行时运行速度更快,相对于作为docker容器而言。因此,尝试找出此问题的根本原因(例如,通过使用卷来降低性能),我编写了这个简单的示例应用程序:

test.cpp

#include <iostream>

void __attribute__ ((noinline)) task()
{
        for (std::size_t i {0}; i < 1000000000; ++i)
        {
                double a { static_cast<double>(rand())/RAND_MAX };
                double b { static_cast<double>(rand())/RAND_MAX };

                double c { a * b };

                c += 1;
        }

}

int main(int argc, char** argv)
{
        task();
}

我编译时使用的是:

$ g++ -pg -O3 -o test test.cpp

运行结果应用程序后,我从gprof获得了此结果:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  Ts/call  Ts/call  name
100.70      0.36     0.36                             task()
  0.00      0.36     0.00        1     0.00     0.00  _GLOBAL__sub_I__Z4taskv

 %         the percentage of the total running time of the
time       program used by this function.

cumulative a running sum of the number of seconds accounted
 seconds   for by this function and those listed above it.

 self      the number of seconds accounted for by this
seconds    function alone.  This is the major sort for this
           listing.

calls      the number of times this function was invoked, if
           this function is profiled, else blank.

 self      the average number of milliseconds spent in this
ms/call    function per call, if this function is profiled,
       else blank.

 total     the average number of milliseconds spent in this
ms/call    function and its descendents per call, if this
       function is profiled, else blank.

name       the name of the function.  This is the minor sort
           for this listing. The index shows the location of
       the function in the gprof listing. If the index is
       in parenthesis it shows where it would appear in
       the gprof listing if it were to be printed.


Copyright (C) 2012-2018 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.


             Call graph (explanation follows)


granularity: each sample hit covers 2 byte(s) for 2.76% of 0.36 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]    100.0    0.36    0.00                 task() [1]
-----------------------------------------------
                0.00    0.00       1/1           __libc_csu_init [15]
[9]      0.0    0.00    0.00       1         _GLOBAL__sub_I__Z4taskv [9]
-----------------------------------------------

 This table describes the call tree of the program, and was sorted by
 the total amount of time spent in each function and its children.

 Each entry in this table consists of several lines.  The line with the
 index number at the left hand margin lists the current function.
 The lines above it list the functions that called this function,
 and the lines below it list the functions this one called.
 This line lists:
     index  A unique number given to each element of the table.
        Index numbers are sorted numerically.
        The index number is printed next to every function name so
        it is easier to look up where the function is in the table.

     % time This is the percentage of the `total' time that was spent
        in this function and its children.  Note that due to
        different viewpoints, functions excluded by options, etc,
        these numbers will NOT add up to 100%.

     self   This is the total amount of time spent in this function.

     children   This is the total amount of time propagated into this
        function by its children.

     called This is the number of times the function was called.
        If the function called itself recursively, the number
        only includes non-recursive calls, and is followed by
        a `+' and the number of recursive calls.

     name   The name of the current function.  The index number is
        printed after it.  If the function is a member of a
        cycle, the cycle number is printed between the
        function's name and the index number.


 For the function's parents, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the function into this parent.

     children   This is the amount of time that was propagated from
        the function's children into this parent.

     called This is the number of times this parent called the
        function `/' the total number of times the function
        was called.  Recursive calls to the function are not
        included in the number after the `/'.

     name   This is the name of the parent.  The parent's index
        number is printed after it.  If the parent is a
        member of a cycle, the cycle number is printed between
        the name and the index number.

 If the parents of the function cannot be determined, the word
 `<spontaneous>' is printed in the `name' field, and all the other
 fields are blank.

 For the function's children, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the child into the function.

     children   This is the amount of time that was propagated from the
        child's children to the function.

     called This is the number of times the function called
        this child `/' the total number of times the child
        was called.  Recursive calls by the child are not
        listed in the number after the `/'.

     name   This is the name of the child.  The child's index
        number is printed after it.  If the child is a
        member of a cycle, the cycle number is printed
        between the name and the index number.

 If there are any cycles (circles) in the call graph, there is an
 entry for the cycle-as-a-whole.  This entry shows who called the
 cycle (as parents) and the members of the cycle (as children.)
 The `+' recursive calls entry shows the number of function calls that
 were internal to the cycle, and the calls entry for each member shows,
 for that member, how many times it was called from other members of
 the cycle.


Copyright (C) 2012-2018 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.


Index by function name

   [9] _GLOBAL__sub_I__Z4taskv [1] task()

因此,task()函数耗时约0.36s。

现在,我想尝试在Docker容器中运行相同的应用程序。由于我的主机操作系统是ubuntu 18.04,因此我将ubuntu:18.04用作基本映像。我使用了这个Dockerfile:

Dockerfile

FROM ubuntu:18.04

# Install g++ and gcc
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    build-essential \
    g++ \
    gcc \
    && rm -rf /var/lib/apt/lists/*

# Copy the test source file to /test/
RUN mkdir /test
COPY ./test.cpp /test/

# Compile the test application
WORKDIR /test
RUN g++ -pg -O3 -o test test.cpp

我使用以下图像构建图像:

$ docker image build -t docker-test .

然后运行:

$ docker container run -ti --rm docker-test

一旦我运行了测试应用程序并从gprof中获得了此结果:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  Ts/call  Ts/call  name
100.70      0.58     0.58                             task()
  0.00      0.58     0.00        1     0.00     0.00  _GLOBAL__sub_I__Z4taskv

 %         the percentage of the total running time of the
time       program used by this function.

cumulative a running sum of the number of seconds accounted
 seconds   for by this function and those listed above it.

 self      the number of seconds accounted for by this
seconds    function alone.  This is the major sort for this
           listing.

calls      the number of times this function was invoked, if
           this function is profiled, else blank.

 self      the average number of milliseconds spent in this
ms/call    function per call, if this function is profiled,
       else blank.

 total     the average number of milliseconds spent in this
ms/call    function and its descendents per call, if this
       function is profiled, else blank.

name       the name of the function.  This is the minor sort
           for this listing. The index shows the location of
       the function in the gprof listing. If the index is
       in parenthesis it shows where it would appear in
       the gprof listing if it were to be printed.


Copyright (C) 2012-2018 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.


             Call graph (explanation follows)


granularity: each sample hit covers 2 byte(s) for 1.71% of 0.58 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]    100.0    0.58    0.00                 task() [1]
-----------------------------------------------
                0.00    0.00       1/1           __libc_csu_init [15]
[9]      0.0    0.00    0.00       1         _GLOBAL__sub_I__Z4taskv [9]
-----------------------------------------------

 This table describes the call tree of the program, and was sorted by
 the total amount of time spent in each function and its children.

 Each entry in this table consists of several lines.  The line with the
 index number at the left hand margin lists the current function.
 The lines above it list the functions that called this function,
 and the lines below it list the functions this one called.
 This line lists:
     index  A unique number given to each element of the table.
        Index numbers are sorted numerically.
        The index number is printed next to every function name so
        it is easier to look up where the function is in the table.

     % time This is the percentage of the `total' time that was spent
        in this function and its children.  Note that due to
        different viewpoints, functions excluded by options, etc,
        these numbers will NOT add up to 100%.

     self   This is the total amount of time spent in this function.

     children   This is the total amount of time propagated into this
        function by its children.

     called This is the number of times the function was called.
        If the function called itself recursively, the number
        only includes non-recursive calls, and is followed by
        a `+' and the number of recursive calls.

     name   The name of the current function.  The index number is
        printed after it.  If the function is a member of a
        cycle, the cycle number is printed between the
        function's name and the index number.


 For the function's parents, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the function into this parent.

     children   This is the amount of time that was propagated from
        the function's children into this parent.

     called This is the number of times this parent called the
        function `/' the total number of times the function
        was called.  Recursive calls to the function are not
        included in the number after the `/'.

     name   This is the name of the parent.  The parent's index
        number is printed after it.  If the parent is a
        member of a cycle, the cycle number is printed between
        the name and the index number.

 If the parents of the function cannot be determined, the word
 `<spontaneous>' is printed in the `name' field, and all the other
 fields are blank.

 For the function's children, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the child into the function.

     children   This is the amount of time that was propagated from the
        child's children to the function.

     called This is the number of times the function called
        this child `/' the total number of times the child
        was called.  Recursive calls by the child are not
        listed in the number after the `/'.

     name   This is the name of the child.  The child's index
        number is printed after it.  If the child is a
        member of a cycle, the cycle number is printed
        between the name and the index number.

 If there are any cycles (circles) in the call graph, there is an
 entry for the cycle-as-a-whole.  This entry shows who called the
 cycle (as parents) and the members of the cycle (as children.)
 The `+' recursive calls entry shows the number of function calls that
 were internal to the cycle, and the calls entry for each member shows,
 for that member, how many times it was called from other members of
 the cycle.


Copyright (C) 2012-2018 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.


Index by function name

   [9] _GLOBAL__sub_I__Z4taskv [1] task()

因此,相同的task()函数花费的时间约为0.58秒,相对于在主机中运行它要慢将近2倍。

为什么应用程序在Docker容器中运行缓慢?难道我做错了什么?还是有提高性能的方法?

performance docker
1个回答
1
投票

谢谢大家的评论。正如Jérôme Richard所提到的,我的测试结果确实是可疑的。另外,我在接下来的几天多次运行相同的测试,并且获得了不同的结果,大多数结果的执行时间等于在主机中获得的执行时间。因此,我可能与同时运行的其他Docker容器并行运行我的测试,这些容器消耗大量CPU(我当时是同一主机上的其他繁重测试)。

因此,我决定重新开始,这次我尝试了要尝试优化并重复测试的应用程序的实际代码。这是我这次使用的代码:

app.h

#include <iostream>
#include <fstream>
#include <vector>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <assert.h>
#include <numeric>
#include <mutex>

template<typename T>
class Filter {
public:
    Filter(std::size_t numberChannels);

    void process(const std::vector<T>& input, std::vector<T>& outData);
private:
    std::size_t          numCh;
        std::size_t          order;
        double               gain;
        std::vector<double>  a;
        std::vector<double>  b;
        std::size_t          currentBlockIndex;
        std::size_t          currentIndex;
        std::vector<double>  x;
        std::vector<double>  y;
};

template<typename T>
void writeVectToFile(const std::vector<T>& v, const std::string& fileName);

app.cpp

#include "app.h"

const std::size_t numSamples { 1000000 };

template<typename T>
Filter<T>::Filter(std::size_t numberChannels)
:
    numCh             { numberChannels      },
    order             { 4                   },
    gain              { 1                   },
    a                 { 1.0, -3.74145562, 5.25726624, -3.28776591,  0.77203984 },
    b                 { 5.28396689e-06, 2.11358676e-05, 3.17038014e-05, 2.11358676e-05, 5.28396689e-06 },
    currentBlockIndex { order               },
    currentIndex      { 0                   },
    x                 ( (order +1) * numCh  ),
    y                 ( (order +1) * numCh  )
{
}

template<typename T>
void __attribute__ ((noinline)) Filter<T>::process(const std::vector<T>& inputData, std::vector<T>& outputData)
{
    if (currentIndex == order)
        currentIndex = 0;
    else
        ++currentIndex;

    std::vector<double>::iterator           xCh    { x.begin() + currentIndex };
    std::vector<double>::iterator           yCh    { y.begin() + currentIndex };
    std::vector<double>::const_iterator     aIt    { a.begin()                };
    std::vector<double>::const_iterator     bIt    { b.begin()                };
    typename std::vector<T>::const_iterator dataIt { inputData.begin()        };

    for (std::size_t ch{0}; ch < numCh; ++ch, xCh += order + 1, yCh += order + 1)
    {
        *xCh = static_cast<double>(*dataIt++);
        *yCh= *bIt * *xCh;
    }

    std::size_t previousIndex { currentIndex };
    std::vector<double>::const_iterator xChPrev;
    std::vector<double>::const_iterator yChPrev;

    for (std::size_t t{1}; t < order + 1; ++t)
    {
        if (previousIndex == 0)
            previousIndex = order;
        else
            --previousIndex;

        yCh     = y.begin() + currentIndex;
        xChPrev = x.begin() + previousIndex;
        yChPrev = y.begin() + previousIndex;
        ++aIt;
        ++bIt;

        for (std::size_t ch{0}; ch < numCh; ++ch, yCh += order + 1, xChPrev += order + 1, yChPrev += order + 1)
        {
            *yCh += *bIt * *xChPrev - *aIt * *yChPrev;
        }
    }

    yCh = y.begin() + currentIndex;
    typename std::vector<T>::iterator outIt(outputData.begin());
    for (std::size_t ch{0}; ch < numCh; ++ch, yCh += order + 1)
    {
        *yCh /= a[0];
        *outIt++ = static_cast<T>(*yCh * gain);
    }
}

template<typename T>
void writeVectToFile(const std::vector<T>& v, const std::string& fileName)
{
    std::ofstream outFile(fileName);
    for (const auto &e : v) outFile << e << "\n";
}

int main(int argc, char* argv[])
{
    const std::size_t numberChannels { 2000 };

    std::vector<int32_t> inputData  ( numberChannels );
    std::vector<int32_t> outputData ( numberChannels );
    std::vector<int32_t> sampleIn   ( numSamples     );
    std::vector<int32_t> sampleOut  ( numSamples     );

    // Create filter object
    Filter<int32_t> f(numberChannels);

    // Send 'numSamples' random values through the filter
    for(std::size_t i {0}; i < numSamples; ++i)
    {
        // Generate random samples
            for (auto &d: inputData)
            d = static_cast<int32_t>( (static_cast<double>(rand())/RAND_MAX) * (2147483647.0) );

        f.process(inputData, outputData);

        // Get the first input and output value
        // They will be use to validate the result
        sampleIn[i]  = inputData[0];
        sampleOut[i] = outputData[0];
    }

    // Write the result to disk
    writeVectToFile( sampleIn,  "x.dat" );
    writeVectToFile( sampleOut, "y.dat" );
}

我使用此Makefile编译:

Makefile

CXX = g++
CXXFLAGS = -Wall -g -O3 -pg

%.o: %.cpp
        $(CXX) -c -o $@ $< $(CXXFLAGS)

app: app.o
        $(CXX) -o $@ $^ $(CXXFLAGS)

clean:
        rm -rf app app.o *.dat gmon.out

并得到此结果:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  Ts/call  Ts/call  name
100.11     19.81    19.81                             Filter<int>::process(std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> >&)
  0.05     19.82     0.01                             void writeVectToFile<int>(std::vector<int, std::allocator<int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
  0.00     19.82     0.00        1     0.00     0.00  _GLOBAL__sub_I_main

 %         the percentage of the total running time of the
time       program used by this function.

cumulative a running sum of the number of seconds accounted
 seconds   for by this function and those listed above it.

 self      the number of seconds accounted for by this
seconds    function alone.  This is the major sort for this
           listing.

calls      the number of times this function was invoked, if
           this function is profiled, else blank.

 self      the average number of milliseconds spent in this
ms/call    function per call, if this function is profiled,
       else blank.

 total     the average number of milliseconds spent in this
ms/call    function and its descendents per call, if this
       function is profiled, else blank.

name       the name of the function.  This is the minor sort
           for this listing. The index shows the location of
       the function in the gprof listing. If the index is
       in parenthesis it shows where it would appear in
       the gprof listing if it were to be printed.


Copyright (C) 2012-2018 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.


             Call graph (explanation follows)


granularity: each sample hit covers 2 byte(s) for 0.05% of 19.82 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]     99.9   19.81    0.00                 Filter<int>::process(std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> >&) [1]
-----------------------------------------------
                                                 <spontaneous>
[2]      0.1    0.01    0.00                 void writeVectToFile<int>(std::vector<int, std::allocator<int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [2]
-----------------------------------------------
                0.00    0.00       1/1           __libc_csu_init [19]
[10]     0.0    0.00    0.00       1         _GLOBAL__sub_I_main [10]
-----------------------------------------------

 This table describes the call tree of the program, and was sorted by
 the total amount of time spent in each function and its children.

 Each entry in this table consists of several lines.  The line with the
 index number at the left hand margin lists the current function.
 The lines above it list the functions that called this function,
 and the lines below it list the functions this one called.
 This line lists:
     index  A unique number given to each element of the table.
        Index numbers are sorted numerically.
        The index number is printed next to every function name so
        it is easier to look up where the function is in the table.

     % time This is the percentage of the `total' time that was spent
        in this function and its children.  Note that due to
        different viewpoints, functions excluded by options, etc,
        these numbers will NOT add up to 100%.

     self   This is the total amount of time spent in this function.

     children   This is the total amount of time propagated into this
        function by its children.

     called This is the number of times the function was called.
        If the function called itself recursively, the number
        only includes non-recursive calls, and is followed by
        a `+' and the number of recursive calls.

     name   The name of the current function.  The index number is
        printed after it.  If the function is a member of a
        cycle, the cycle number is printed between the
        function's name and the index number.


 For the function's parents, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the function into this parent.

     children   This is the amount of time that was propagated from
        the function's children into this parent.

     called This is the number of times this parent called the
        function `/' the total number of times the function
        was called.  Recursive calls to the function are not
        included in the number after the `/'.

     name   This is the name of the parent.  The parent's index
        number is printed after it.  If the parent is a
        member of a cycle, the cycle number is printed between
        the name and the index number.

 If the parents of the function cannot be determined, the word
 `<spontaneous>' is printed in the `name' field, and all the other
 fields are blank.

 For the function's children, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the child into the function.

     children   This is the amount of time that was propagated from the
        child's children to the function.

     called This is the number of times the function called
        this child `/' the total number of times the child
        was called.  Recursive calls by the child are not
        listed in the number after the `/'.

     name   This is the name of the child.  The child's index
        number is printed after it.  If the child is a
        member of a cycle, the cycle number is printed
        between the name and the index number.

 If there are any cycles (circles) in the call graph, there is an
 entry for the cycle-as-a-whole.  This entry shows who called the
 cycle (as parents) and the members of the cycle (as children.)
 The `+' recursive calls entry shows the number of function calls that
 were internal to the cycle, and the calls entry for each member shows,
 for that member, how many times it was called from other members of
 the cycle.


Copyright (C) 2012-2018 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.


Index by function name

  [10] _GLOBAL__sub_I_main (app.cpp) [2] void writeVectToFile<int>(std::vector<int, std::allocator<int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [1] Filter<int>::process(std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> >&)

大约20秒钟调用方法Filter<T>::process 1e6次。

然后我用(这一次我也复制了主机中生成的二进制文件)创建了一个Docker映像:

Dockerfile

FROM ubuntu:18.04

# Install g++ and gcc
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    build-essential \
    gcc \
    g++ \
    && rm -rf /var/lib/apt/lists/*

# Copy the test source file to /test/
RUN mkdir /test
COPY * /test/

# Copy the binary used for testing in the host
RUN mkdir /test-host
COPY ./app /test-host/app

# Compile the test application
WORKDIR /test
RUN make clean && make

我用以下图像构建图像:

$ docker image build -t docker-test --no-cache .

并与:一起运行]

docker container run -ti --rm docker-test

我得到:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  Ts/call  Ts/call  name
100.11     21.71    21.71                             Filter<int>::process(std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> >&)
  0.05     21.72     0.01                             void writeVectToFile<int>(std::vector<int, std::allocator<int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
  0.00     21.72     0.00        1     0.00     0.00  _GLOBAL__sub_I_main

 %         the percentage of the total running time of the
time       program used by this function.

cumulative a running sum of the number of seconds accounted
 seconds   for by this function and those listed above it.

 self      the number of seconds accounted for by this
seconds    function alone.  This is the major sort for this
           listing.

calls      the number of times this function was invoked, if
           this function is profiled, else blank.

 self      the average number of milliseconds spent in this
ms/call    function per call, if this function is profiled,
       else blank.

 total     the average number of milliseconds spent in this
ms/call    function and its descendents per call, if this
       function is profiled, else blank.

name       the name of the function.  This is the minor sort
           for this listing. The index shows the location of
       the function in the gprof listing. If the index is
       in parenthesis it shows where it would appear in
       the gprof listing if it were to be printed.


Copyright (C) 2012-2018 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.


             Call graph (explanation follows)


granularity: each sample hit covers 2 byte(s) for 0.05% of 21.72 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]    100.0   21.71    0.00                 Filter<int>::process(std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> >&) [1]
-----------------------------------------------
                                                 <spontaneous>
[2]      0.0    0.01    0.00                 void writeVectToFile<int>(std::vector<int, std::allocator<int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [2]
-----------------------------------------------
                0.00    0.00       1/1           __libc_csu_init [19]
[10]     0.0    0.00    0.00       1         _GLOBAL__sub_I_main [10]
-----------------------------------------------

 This table describes the call tree of the program, and was sorted by
 the total amount of time spent in each function and its children.

 Each entry in this table consists of several lines.  The line with the
 index number at the left hand margin lists the current function.
 The lines above it list the functions that called this function,
 and the lines below it list the functions this one called.
 This line lists:
     index  A unique number given to each element of the table.
        Index numbers are sorted numerically.
        The index number is printed next to every function name so
        it is easier to look up where the function is in the table.

     % time This is the percentage of the `total' time that was spent
        in this function and its children.  Note that due to
        different viewpoints, functions excluded by options, etc,
        these numbers will NOT add up to 100%.

     self   This is the total amount of time spent in this function.

     children   This is the total amount of time propagated into this
        function by its children.

     called This is the number of times the function was called.
        If the function called itself recursively, the number
        only includes non-recursive calls, and is followed by
        a `+' and the number of recursive calls.

     name   The name of the current function.  The index number is
        printed after it.  If the function is a member of a
        cycle, the cycle number is printed between the
        function's name and the index number.


 For the function's parents, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the function into this parent.

     children   This is the amount of time that was propagated from
        the function's children into this parent.

     called This is the number of times this parent called the
        function `/' the total number of times the function
        was called.  Recursive calls to the function are not
        included in the number after the `/'.

     name   This is the name of the parent.  The parent's index
        number is printed after it.  If the parent is a
        member of a cycle, the cycle number is printed between
        the name and the index number.

 If the parents of the function cannot be determined, the word
 `<spontaneous>' is printed in the `name' field, and all the other
 fields are blank.

 For the function's children, the fields have the following meanings:

     self   This is the amount of time that was propagated directly
        from the child into the function.

     children   This is the amount of time that was propagated from the
        child's children to the function.

     called This is the number of times the function called
        this child `/' the total number of times the child
        was called.  Recursive calls by the child are not
        listed in the number after the `/'.

     name   This is the name of the child.  The child's index
        number is printed after it.  If the child is a
        member of a cycle, the cycle number is printed
        between the name and the index number.

 If there are any cycles (circles) in the call graph, there is an
 entry for the cycle-as-a-whole.  This entry shows who called the
 cycle (as parents) and the members of the cycle (as children.)
 The `+' recursive calls entry shows the number of function calls that
 were internal to the cycle, and the calls entry for each member shows,
 for that member, how many times it was called from other members of
 the cycle.


Copyright (C) 2012-2018 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.


Index by function name

  [10] _GLOBAL__sub_I_main (app.cpp) [2] void writeVectToFile<int>(std::vector<int, std::allocator<int> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) [1] Filter<int>::process(std::vector<int, std::allocator<int> > const&, std::vector<int, std::allocator<int> >&)

我使用在主机中编译的二进制文件和在Docker映像中编译的二进制文件都获得了几乎相同的结果。

这次,我获得了在主机中运行与在容器中运行几乎相同的结果(两种情况都大约20秒)。因此,在容器中运行时,我看不到任何性能影响。

我主机中的g ++编译器是:

$ g++ --version
g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我容器中的g ++编译器为:

# g++ --version
g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我正在使用此docker版本:

$ docker version
Client: Docker Engine - Community
 Version:           19.03.7
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        7141c199a2
 Built:             Wed Mar  4 01:22:36 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.7
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       7141c199a2
  Built:            Wed Mar  4 01:21:08 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
© www.soinside.com 2019 - 2024. All rights reserved.