Guest Posted January 31, 2019 hello, I'm using a wrapper of the Intel TBB memory manager, working perfectly, then I have discovered a grave bug that don't permits to replace the default MM in Tokio, RIO if you use new compiler features. This happens when you use anonymous functions with generics, for example you call inside this function another function passing a PPType the function calls New() on the result then using fillchar sizeof ^PType ok, the pointer is not passing between the calling functions, generating Violation Access Share this post Link to post
Stefan Glienke 2002 Posted January 31, 2019 From looking at the callstack I am pretty sure there is a defect it's in your code namely in TIocpCrossSocket._NewAccept or the code that calls this method in case of AListen being nil. Share this post Link to post
Sherlock 663 Posted January 31, 2019 Are you able to reproduce this bug in a somewhat simpler example? Share this post Link to post
Guest Posted January 31, 2019 It’s a nice library called delphi-cross-socket why default mm is tolerant to these errors? Later I post both TBB wrapper and the lib, tjanks Share this post Link to post
Stefan Glienke 2002 Posted January 31, 2019 (edited) Try removing the inline from function TIocpCrossSocket._NewIoData: PPerIoData; - possible that it trips over something there - apart from that I don't see how this could be related to anonymous methods. The variable assigned to is a local variable of a regular method and there are no anonymous methods in procedure TIocpCrossSocket._NewAccept(AListen: ICrossListen); that could change the location of that variable to somewhere else than the stack. Possible that the TBB code is sensitive to some garbage value in a volatile register that it does not properly check for. Edited January 31, 2019 by Stefan Glienke Share this post Link to post
Guest Posted January 31, 2019 hi, if you have time https://github.com/winddriver/Delphi-Cross-Socket a great library to do async scalable server (really well done the windows counterpart), check for example the websocketdemo extract the attached file there are two libs and relative units, I did custom DLL from Intel TBB and Intel IPP projects because I'm near to release on github a Isapi deflate filter for IIS 10 (5x faster vs system) Put RDPMM64 as first unit to replace the MM and debug websocketdemo. Feel free to use internally those libs for your purposes, but please don't redistribute, because in the actual form they violate 2 licenses (microsoft requires to link to visualC redistributable setup (instead I did smart linking inside one small dll), same thing Intel requires to redistribute whole libraries IPP, both tens of megabytes....) anyway with those patches (MM, fillchar, move, pos) some server benchmark shows 3x improvement in quad core server (multithreaded distributed load) ok, let me know, I'm here if you need, thanks IntelIPP_Delphi.zip Share this post Link to post
Guest Posted January 31, 2019 (I forgot, the patches works perfectly with big size Delphi projects, I need figure out the troubles with DelphiCrossSocket...) Share this post Link to post
Sherlock 663 Posted January 31, 2019 I'm sorry to insist but libraries are not simple. And neither is the need to install one to reproduce a bug, that is supposed to be rooted in the IDE. Share this post Link to post
Stefan Glienke 2002 Posted January 31, 2019 (edited) There clearly is a race condition somewhere in the SeaMM.dll - either it works, or it raises AVs until it stackoverflows or it gets stuck inside a loop (keep clicking Start/Stop if it does not raise AV/SO) with these instructions: 00007FF9B59FB520 664103D0 add dx,r8w 00007FF9B59FB524 488BD9 mov rbx,rcx 00007FF9B59FB527 66895774 mov [rdi+$74],dx 00007FF9B59FB52B 488B01 mov rax,[rcx] 00007FF9B59FB52E 488BC8 mov rcx,rax 00007FF9B59FB531 4883C801 or rax,$01 00007FF9B59FB535 4883F801 cmp rax,$01 00007FF9B59FB539 75E5 jnz $00007ff9b59fb520 Anyway as you seem to be the author/modifier of that code you should be able to debug that yourself. As soon as I put a breakpoint I could not get the AV - which confirms my guess about the race condition. Edited January 31, 2019 by Stefan Glienke Share this post Link to post
Guest Posted January 31, 2019 (edited) So the problem is the Intel TBB? Maybe I forgot a multithread flag /MD /MT etc. compiling it, hmmm... I try 😕 thanks for your kind help Edited January 31, 2019 by Guest Share this post Link to post
Guest Posted January 31, 2019 (edited) ok just tried unmodified Intel compiled DLL https://github.com/01org/tbb/releases (you can check bin folder tbbmalloc.dll) the problem persist, so in my opinion cannot be a problem of this library, but somewhere in the compiler low level / RTL / manager memory? (sorry if I insist, but the libraries works perfectly with dozen of delphi projects, big, a variety of components, and the problem appears only with this Delphi Cross Socket IoCompletionPort) Edited January 31, 2019 by Guest Share this post Link to post
Guest Posted January 31, 2019 (edited) I have solved with this: IsMultiThread:=True; at begin but this isn't a old setting? problem persist just to clarify then I stop to be boring, imho the thing deserves a look, because for example using TParallel.For and other system.threadpool with massive concurrency I get no problem at all... Something of odd should be (sorry if I'm wrong) Edited January 31, 2019 by Guest Share this post Link to post
Микола Петрівський 10 Posted February 1, 2019 You should try other memory managers and see how your test app behaves. There are plenty of them: ScaleMM, SapMM, Nexus Memory Manager. Share this post Link to post
Guest Posted February 1, 2019 (edited) yes, indeed, the problem appears only using Intel TBB I have tested FastMM-avx, ScaleMM2, Google tcMalloc, BrainMM curiously, under Windows Server 2016, the better performing heap manager (I'm using apachebench to do a test with 1000 concurrent sockets) is the OS (using directly heapalloc, heapfree...) I would like to notify IntelTBB github about their problem thanks all for the help btw. https://docs.microsoft.com/en-us/windows/desktop/memory/low-fragmentation-heap Edited February 2, 2019 by Guest Share this post Link to post
Stefan Glienke 2002 Posted February 1, 2019 (edited) 1 hour ago, RDPasqua said: better performing speed, min/max memory footprint, fragmentation, single/multi thread, sharing memory across threads? Edited February 1, 2019 by Stefan Glienke Share this post Link to post
Guest Posted February 1, 2019 (edited) I have tested only the application throughput speed, I don't know if it's prone to fragmentation (probably the big advantage of adopting a MM layer is avoid this) How to test other parameters you told? (btw. I see C++ coders use msvcrt malloc or directly the OS heap allocator api) https://github.com/01org/tbb/issues/120#issuecomment-459776671 https://github.com/winddriver/Delphi-Cross-Socket/issues/39 (I miss Per Larsen SleuthQA, I try now madExcept, or do you know any good QA mem checker?) Edited February 1, 2019 by Guest Share this post Link to post
Guest Posted February 1, 2019 I have done a quick look to the source where exception happens, well, I have not seen errors, also the code seems very well designed with interfaces, anonymous methods, abstraction, generics, correct overloading and great management of windows api I have done a try to resemble the function with the fault, calling a new() record within a loop, without troubles ... :-zzz Share this post Link to post
Микола Петрівський 10 Posted February 4, 2019 On 2/1/2019 at 4:25 PM, RDPasqua said: (I miss Per Larsen SleuthQA, I try now madExcept, or do you know any good QA mem checker?) EurekaLog is also good. And for debug builds you can use SafeMM. Share this post Link to post
Erwin Mouthaan 7 Posted February 4, 2019 On 2/1/2019 at 3:25 PM, RDPasqua said: (I miss Per Larsen SleuthQA, I try now madExcept, or do you know any good QA mem checker?) Nexus Quality Suite comes to mind. https://www.nexusdb.com/support/index.php?q=node/27156 Trial version is available. https://www.nexusdb.com/support/index.php?q=NQS_Trial Share this post Link to post