Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perfomance degradation in multi thread #217

Open
schadin opened this issue Jan 20, 2023 · 4 comments
Open

Perfomance degradation in multi thread #217

schadin opened this issue Jan 20, 2023 · 4 comments
Labels

Comments

@schadin
Copy link

schadin commented Jan 20, 2023

Hi. I'm development of dll export data to kafka. Library is a plugin for other windows native application. I'm exported method from my dll by Dllexport. All operations available by way of one Core class. Exported methods call method of Core class.
Dll has two mode of work:

  • Stub - generate message and serialize into byte array without send to kafka.
  • Kafka - generate message and serialize into byte array with send to kafka.

For test i wrote two applications: native and .net. Native call dll by exported method, .net by Core class.
In Stub mode throughput - 100-120k per second in both applications.
In Kafka mode and single threaded both application ~10k per second.
In Kafka mode and multi threaded .net application have throughput 50-55k per second.
But native application - 30k per second.

How can I find out the reasons for the degradation on performance with call through exported methods?

  • DllExport -version: 1.7.4
  • Copy-paste from Data tab:
Installed: True; 1.7.4+c1cc52f; invoked: 1.7.4
Project type: Cs
Storage: ProjectFiles
Compiler.Platform: x64
Compiler.ordinalsBase: 1
Compiler.rSysObj: True
Compiler.ourILAsm: True
Compiler.customILAsm: 
Compiler.genExpLib: True
Compiler.peCheck: PeIl
Compiler.patches: 3
PreProc.Type: ILMerge, DebugInfo
PreProc.Cmd: Avro.dll Confluent.Kafka.dll log4net.dll KafkaExport.Shared.dll Newtonsoft.Json.dll System.Buffers.dll System.Memory.dll System.Runtime.CompilerServices.Unsafe.dll YamlDotNet.dll
PostProc.Type: None
PostProc.ProcEnv: $(SolutionPath);$(MSBuildThisFileFullPath)
PostProc.Cmd: 
SignAssembly: 
Identifier: C75010CE-13F5-443D-A6C7-E86AE18B9CA0
Instance: C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\amd64\MSBuild.exe
Project path: W:\KafkaExport\KafkaExport.csproj
Action: Configure
PlatformTarget: x64
TargetFramework: 
TargetFrameworks: 
TargetFrameworkVersion: v4.7
RootNamespace: KafkaExport
AssemblyName: KafkaExport
MgrArgs: 
MetaLib: tools\raw\lib\net20\DllExport.dll
MetaCor: tools\raw\lib\netstd\DllExport.dll
Proxy: 
StoragePath: .net.dllexport.targets
ddNS: KafkaExport
ddNS max buffer: 500
UseCecil: True
intermediateFiles: False
timeout: 30000
Options: None
RootPath: W:\kafka-export\src\
PkgPath: W:\kafka-export\src\packages\\DllExport.1.7.4\
SlnFile: 
SlnDir: W:\kafka-export\src\
DxpTarget: tools\net.r_eg.DllExport.targets
MsgGuiLevel: -1
LockIfError: 

Thank you.

@3F
Copy link
Owner

3F commented Jan 24, 2023 via email

@schadin
Copy link
Author

schadin commented Jan 26, 2023

Hello, If I understood correctly, the problem may be related to the way the both processes interop using p/invoke. This may affect performance (of course) same as here: KirillOsenkov/Benchmarks#5 (comment) Try to reduce frequent interruption via fragmented sending of data with caching Or look at calling your code, Maybe there are some marshaling issue and so on. https://github.com/3F/DllExport/wiki/Quick-start#about-data-types Try profiling and make sure you don't have the debug config anywhere

On 20.01.2023 12:06, Alexey Schadin wrote: Message ID: @.***>

Thank you for reply.
I've rewritting multithread from ThreadPool to TPL DataFlow, it increase throughput library.
If not send data to Kafka throughput is 100k-150k messages per seconds.
If send data to Kafka throughput data flow from exported method (35k) lower then .net application(80k).
I'am tested variant with when .NET applicaiton load dll from P/Invoke, throughput equals native application (35k).
My coworker think that exported methods limitation threads perfomance. I can't accept or reject it.

I don't know the possible solution. And I'm not sure which way to go.

@3F
Copy link
Owner

3F commented Jan 28, 2023 via email

@3F
Copy link
Owner

3F commented Dec 17, 2024

Please provide some specific example to reproduce the problem.
Because it still looks like a wrong implementation around p/invoke and everything that I mentioned above. Thanks.

In addition, you can compare the speed on the latest stable CI build https://ci.appveyor.com/project/3Fs/dllexport-ix27o/builds/51186002/artifacts and also try to set the following values in your project files:

<Optimize>true</Optimize>
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants