我正在测试和分析我的一个应用程序,该应用程序作为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容器中运行速度较慢?难道我做错了什么?还是有办法提高性能?
答案 0 :(得分:2)
谢谢大家的评论。正如#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);
所述,我的测试结果确实是可疑的。另外,我在接下来的几天多次运行相同的测试,并且获得了不同的结果,大多数结果的执行时间等于在主机中获得的执行时间。因此我可能与同时运行的其他Docker容器并行运行测试,而这些Docker容器消耗大量CPU(我当时是同一主机上的其他繁重测试)。
因此,我决定重新开始,这次我尝试了要尝试优化并重复测试的应用程序的实际代码。这是我这次使用的代码:
app.h
#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" );
}
app.cpp
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
我使用此Makefile进行了编译:
制作文件
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> >&)
并得到以下结果:
Filter<T>::process
大约20秒钟调用方法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
1e6次。
然后我使用以下方法创建一个Docker映像(这次我还复制了主机中生成的二进制文件):
Dockerfile
$ 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> >&)
然后我得到了
$ 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映像编译的二进制文件都获得了几乎相同的结果。
这一次,我获得了在主机中运行与在容器中运行几乎相同的结果(两种情况下大约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 ++编译器是:
$ 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
我正在使用此docker版本:
using System;
using System.Reflection;
using System.Threading;
namespace MyRTD
{
class Program
{
// ProgIDs for COM classes.
private const String RTDProgID = "MyRTD.RTD";
private const String RTDUpdateEventProgID = "MyRTD.UpdateEvent";
private const String RTDEXEProgID = "MyRTDEXE.RTD";
private const String RTDEXEUpdateEventProgID = "MyRTDEXE.UpdateEvent";
// Dummy topic.
private const int topicID = 12345;
private const String topic = "topic";
static void Main(string[] args)
{
Console.WriteLine("Test in-process (DLL) RTD server.");
TestMyRTD(RTDProgID,RTDUpdateEventProgID);
Console.WriteLine("Test out-of-process (EXE) RTD server.");
TestMyRTD(RTDEXEProgID,RTDEXEUpdateEventProgID);
Console.WriteLine("Press enter to exit ...");
Console.ReadLine();
}
static void TestMyRTD(String rtdID, String eventID)
{
try
{
// Create the RTD server.
Type rtd;
Object rtdServer = null;
rtd = Type.GetTypeFromProgID(rtdID);
rtdServer = Activator.CreateInstance(rtd);
Console.WriteLine("rtdServer = {0}", rtdServer.ToString());
// Create a callback event.
Type update;
Object updateEvent = null;
update = Type.GetTypeFromProgID(eventID);
updateEvent = Activator.CreateInstance(update);
Console.WriteLine("updateEvent = {0}", updateEvent.ToString());
// Start the RTD server.
Object[] param = new Object[1];
param[0] = updateEvent;
MethodInfo method = rtd.GetMethod("ServerStart");
Object ret; // Return value.
ret = method.Invoke(rtdServer, param);
Console.WriteLine("ret for 'ServerStart()' = {0}", ret.ToString());
// Request data from the RTD server.
Object[] topics = new Object[1];
topics[0] = topic;
Boolean newData = true; // Request new data, not cached data.
param = new Object[3];
param[0] = topicID;
param[1] = topics;
param[2] = newData;
method = rtd.GetMethod("ConnectData");
ret = method.Invoke(rtdServer, param);
Console.WriteLine("ret for 'ConnectData()' = {0}", ret.ToString());
// Loop and wait for RTD to notify (via callback) that
// data is available.
int count = 0;
do
{
count++;
// Check that the RTD server is still alive.
Object status;
param = null;
method = rtd.GetMethod("Heartbeat");
status = method.Invoke(rtdServer, param);
Console.WriteLine("status for 'Heartbeat()' = {0}", status.ToString());
// Get data from the RTD server.
int topicCount = 0;
param = new Object[1];
param[0] = topicCount;
method = rtd.GetMethod("RefreshData");
Object[,] retval = new Object[2, 1];
retval = (Object[,])method.Invoke(rtdServer, param);
Console.WriteLine("retval for 'RefreshData()' = {0}", retval[1,0].ToString());
// Wait for 2 seconds before getting
// more data from the RTD server.
Thread.Sleep(2000);
} while (count < 5); // Loop 5 times.
// Disconnect from data topic.
param = new Object[1];
param[0] = topicID;
method = rtd.GetMethod("DisconnectData");
method.Invoke(rtdServer, param);
// Shutdown the RTD server.
param = null;
method = rtd.GetMethod("ServerTerminate");
method.Invoke(rtdServer, param);
}
catch (Exception e)
{
Console.WriteLine("Error: {0} ", e.Message);
}
}
}
}