C
C#Sneaky Panda

Help with concurrency blocking issue

I have a small app that runs CPU bound on multiple threads (amount of processors) On one PC it works very well, reaching ~800 iterations/second But on my other PC (Which is actually far superior in all of it's components), it averages on ~200 iterations.. I attached a concurrency visualizer analysis, as you can see it's almost 50% stuck in sync (locks) 2nd image shows a zoom in with a blocking thread which blocks all other threads. Seems to be something regarding the GC. Analysing memory I could not see any weird signs there.. any and all help would be greatly appreciated.
No description
No description
M
mtreit43d ago
Ephemeral GC (gen 0 and gen 1) pauses all threads. If you have a lot of such collections happening it could be impacting you. That would imply your code is doing a lot of memory allocations.
I
IsNotNull43d ago
Is that only true (on workstation GC) if a gen 2 collection is already occurring in the background?
SP
Sneaky Panda43d ago
UPDATE: OK so obviously I rubber ducked this Discord Using GC.TryStartNoGCRegion with a large enough allocation solved the problem
No description
M
mtreit43d ago
Well, gen 2 is different. Gen0 and Gen1 always pause all threads as far as I know. Gen2 can do background collections on separate dedicated threads. TryStartNoGCRegion :tense:
I
IsNotNull43d ago
I was trying to confirm that, but all I found so far was confirmation that it pauses all threads during a 'foreground' G0 or G1 collection (meaning a background G2 is already occuring)
I
IsNotNull43d ago
No description
I
IsNotNull43d ago
The GC docs feel a bit inconsistent. They have contemporary verbiage indicating some features have replaced others and then out-of band warnings claiming some things don't apply if you are using NET FX. Its really hard to tell what applies in a bog standard .NET 5.0+ project by default
SP
Sneaky Panda43d ago
lol yeah I agree but it's a dedicated slave to do bursts of multithreaded map reduction
M
mtreit43d ago
You might look at the code and see if you can allocate less. Sounds like you're doing a lot of small allocations.
SP
Sneaky Panda43d ago
Yeah it's very complex code I inherited, so unfortunately this is the most cost effective workaround I pooled a lot of the smaller allocations where it wasn't deadly scary. uncovered legacy code 🥲 btw, if I wanted to profile this to see where the issue is; which profiler should I use?
M
mtreit43d ago
I usually use PerfView
I
IsNotNull43d ago
The 'fundamentals' GC page mentions this offhand. I bet on CPU bound and allocation heavy code, that the threshold before its worth partitioning data to IPC to child processes to handle is probably a lot lower than most devs expect (assuming the inputs and outputs are reasonable to serialize).
M
mtreit43d ago
The classic advice in performance talks for .NET is "Objects you allocate should either be extremely short lived or live for the entire lifetime of your process." Techniques like pre-allocating everything on startup and using pooling are one way to avoid these kinds of GC pause issues. Easier said than done.
I
IsNotNull43d ago
@mtreit I agree, I just meant that the pauses increase in relative expense with the number of active threads you have. There is some threshold (in allocation rate and active threads) where it costs less to split the work across processes...and I bet its a lower threshold than we would want to know about; probably at a level that most of us would claim its a premature optimization or too annoying/complicated to support in a hand-waivey way. Luckily I'm primarily a web / business / app dev, and 'all cores and CPU bound' work is pretty rare.
M
mtreit43d ago
I'm working on a codebase that is CPU bound for pretty much the first time in my career - most of my previous work was all I/O bound (network calls, database calls.) It's an interesting change.
I
IsNotNull43d ago
I wish I could get onto a project like that. I can't even get MS to review my job applications.
Want results from more Discord servers?
Add your server
More Posts
Frontend not workingI dont really keen on frontend but I think have some knowledge about it would be nice, I'm learning JsonSerializerOptionsTo be continuedC# Dictionary questionHi, if i have a dictionary in C# defined like so: `Dictionary<string, List<int>> test;` and I do `Li✅ Avalonia not showing rows in datagridThere are no rows in my datagrid in Avalonia, the headers are visible. I've checked if my list is emInfinite loop```c# /// ------------------------------------------------------------ /// <summary> /// Creates a sHow to connect my c# backend with the frontend?Hello, I created a ASP NET Core Web Api project with the command dotnet new webapi -minimal. In my ✅ Using `Func<ReadOnlySpan<char>,bool>` but not allowed due to Pointer TypeI am building a parser, and performance is of concern. So instead of allocating infinite strings wheconcurrency and atomicity Asp.net core web api and efcorelet's say there's an endpoint called AssingUser() ,this endpoint assigns one donation to this currenBuilding a generic repository for mongodbhello folks I was thinking build a generic repository structure for mongodb. but someday if i want Reading large xml file from archive by using XmlReader in Parallel modeHello 👋. I am looking for how can I read data from archive xml file in Parallel mode. I have archiResizing the Console window - Console ApplicationHi there, I'm trying to resize the console window in a Console Application. I have tried multiple ✅ Creating a datetime with a timezoneHow do I create a `DateTime` with `new DateTime(2010, 05, 12);` and give it a specific `TimeZoneInfoCustom Newtonsoft JSON deserializationI have a dictionary where: - The key will always be a string - The value will be either: - string Issue with Form.Close() in WinformsI have a custom form called CustomMessageBox In that form, I have a method that defines a button clIssue with IMGUI.Net.Hello, I am creating an ImGUI application and It doesn't let me move the ui across my entire screen,Issue with deserializing Enums in saved JSONHey, I've been trying to deserialize a list of cards I serialized in C#, the issue I'm having is it From HttpClient, can I save/copy the request to share with someone?Is there a way to copy raw request details? For example, I'm looking for a similar output like: -3D Unity RaycastingHi guys, currently working on a puzzle game involving lasers and mirrors, however, have hit a brick Computer Science - Computer ArchitectureOn a 64 bit system (where the bus length and word size are 64 bits) how would we determine the ammouConnecting SQLite in MAUIHow to connect the database without absolute path? If with it, the program works only on the compute