You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bugA problem with current functionality, as opposed to missing functionality (enhancement)frozen-due-to-ageIssues closed and untouched for a long time, together with being locked for discussionneeds-triageNew issues needed to be validated
Often I see people asking why they can’t create more than around 2000 threads in a process. The reason is not that there is any particular limit inherent in Windows. Rather, the programmer failed to take into account the amount of address space each thread uses.
A thread consists of some memory in kernel mode (kernel stacks and object management), some memory in user mode (the thread environment block, thread-local storage, that sort of thing), plus its stack. (Or stacks if you’re on an Itanium system.)
Usually, the limiting factor is the stack size.
This program will typically print a value around 2000 for the number of threads.
Why does it give up at around 2000?
Because the default stack size assigned by the linker is 1MB, and 2000 stacks times 1MB per stack equals around 2GB, which is how much address space is available to user-mode programs.
You can try to squeeze more threads into your process by reducing your stack size, which can be done either by tweaking linker options or manually overriding the stack size passed to the CreateThread functions as described in MSDN.
The post comes from 2005 and seems to relate to a 32-bit installation of Windows only. My installation is 32-bit too, and I have also found
runtime: failed to create new OS thread (have 1192 already; errno=8)
in the "normal" Syncthing log, which would confirm the theory of 2000 threads limitation.
The post mentions making tweaks in the code to "squeak in" more threads. Is this something that could be done in Syncthing, or would rather need to be done in the Golang itself?
Likely the issue is with concurrent I/O, as that has a tendency of spawning more runtime threads. Using the various rate limiters to limit concurrent I/O requests might help.
Likely the issue is with concurrent I/O, as that has a tendency of spawning more runtime threads. Using the various rate limiters to limit concurrent I/O requests might help.
Is this something that needs to be done at the OS level? I do not believe that Windows has this kind of control though. I guess that limiting the folder concurrency in Syncthing could help here, but I prefer to keep it at -1 for other reasons. As long as this was a one-time occurrence, I will probably just ignore it.
I have received no feedback on the Go forums anyway.
I don't know your setup but my guess would be lots of connected devices doing lots of concurrent requests, which we have controls for (max concurrent incoming request data). Folder concurrency might add to it, but I think that should be minor unless you have more than a thousand folders.
Or, well, I do. The panic log shows a large amount of outstanding requests, many blocked on disk I/O. So reducing the max request kib (per folder) and/or folder concurrency should help.
Specifically the MaxConcurrentWrites folder option is 2 by default, while in the panic there are 1184 ongoing write operations on the same folder. Setting that to unlimited is madness. Please always specify any changed configuration when reporting.
Or, well, I do. The panic log shows a large amount of outstanding requests, many blocked on disk I/O. So reducing the max request kib (per folder) and/or folder concurrency should help.
This is a good clue, because while the device does use only flash storage, it is rather slow. I have the folders spread on two different disks.
Built-in eMMC (not great, but passable)
> Disk Random 16.0 Read 30.31 MB/s
> Disk Sequential 64.0 Read 110.89 MB/s
> Disk Sequential 64.0 Write 32.17 MB/s
> Average Read Time with Sequential Writes 0.916 ms
> Latency: 95th Percentile 2.207 ms
> Latency: Maximum 42.122 ms
> Average Read Time with Random Writes 1.118 ms
SD Card (very slow)
> Disk Random 16.0 Read 8.31 MB/s
> Disk Sequential 64.0 Read 19.01 MB/s
> Disk Sequential 64.0 Write 7.67 MB/s
> Average Read Time with Sequential Writes 3.272 ms
> Latency: 95th Percentile 8.560 ms
> Latency: Maximum 435.594 ms
> Average Read Time with Random Writes 7.405 ms
Do you mean tweaking PullerMaxPendingKiB? What value should I change it to though? There is nothing in the Docs explaining it, but I am guessing that it is set using the following code.
Specifically the MaxConcurrentWrites folder option is 2 by default, while in the panic there are 1184 ongoing write operations on the same folder. Setting that to unlimited is madness. Please always specify any changed configuration when reporting.
That's indeed bad. For this particular problem the following proposed change will mitigate it, however we should really fix the folder defaults issue in general. #7069
Should I manually change MaxConcurrentWrites from 0 (set by Syncthing) to 2?
bugA problem with current functionality, as opposed to missing functionality (enhancement)frozen-due-to-ageIssues closed and untouched for a long time, together with being locked for discussionneeds-triageNew issues needed to be validated
Activity
AudriusButkevicius commentedon Oct 28, 2020
This is the OS refusing to start a thread when go asked for it.
None of the code is ours and if anything would be a go runtime bug, but more likely issues with the os running out of handles or something.
tomasz1986 commentedon Oct 28, 2020
It seems that the reason may be https://devblogs.microsoft.com/oldnewthing/?p=34773.
The post comes from 2005 and seems to relate to a 32-bit installation of Windows only. My installation is 32-bit too, and I have also found
in the "normal" Syncthing log, which would confirm the theory of 2000 threads limitation.
The post mentions making tweaks in the code to "squeak in" more threads. Is this something that could be done in Syncthing, or would rather need to be done in the Golang itself?
AudriusButkevicius commentedon Oct 28, 2020
There is not really a concept of a thread in Go, it's all managed by the runtime.
calmh commentedon Oct 29, 2020
Likely the issue is with concurrent I/O, as that has a tendency of spawning more runtime threads. Using the various rate limiters to limit concurrent I/O requests might help.
tomasz1986 commentedon Oct 30, 2020
Is this something that needs to be done at the OS level? I do not believe that Windows has this kind of control though. I guess that limiting the folder concurrency in Syncthing could help here, but I prefer to keep it at
-1for other reasons. As long as this was a one-time occurrence, I will probably just ignore it.I have received no feedback on the Go forums anyway.
calmh commentedon Oct 30, 2020
I don't know your setup but my guess would be lots of connected devices doing lots of concurrent requests, which we have controls for (max concurrent incoming request data). Folder concurrency might add to it, but I think that should be minor unless you have more than a thousand folders.
tomasz1986 commentedon Oct 30, 2020
Hmm, that is strange then, because I have only 4 devices connected. There are 29 folders though, hence the question about folder concurrency.
This is how the device in question looks like. Not a minimal configuration, but also nothing extreme, at least in my eyes.
calmh commentedon Oct 30, 2020
Then I have no good explanation
calmh commentedon Oct 30, 2020
Or, well, I do. The panic log shows a large amount of outstanding requests, many blocked on disk I/O. So reducing the max request kib (per folder) and/or folder concurrency should help.
imsodin commentedon Oct 30, 2020
Specifically the
MaxConcurrentWritesfolder option is 2 by default, while in the panic there are 1184 ongoing write operations on the same folder. Setting that to unlimited is madness. Please always specify any changed configuration when reporting.tomasz1986 commentedon Oct 30, 2020
@calmh
This is a good clue, because while the device does use only flash storage, it is rather slow. I have the folders spread on two different disks.
Do you mean tweaking
PullerMaxPendingKiB? What value should I change it to though? There is nothing in the Docs explaining it, but I am guessing that it is set using the following code.syncthing/lib/model/folder_sendrecv.go
Line 112 in 1a8c10a
syncthing/lib/model/folder_sendrecv.go
Lines 155 to 157 in 1a8c10a
Is there any way to know what value is currently being used for
PullerMaxPendingKiB?@imsodin
The de facto default value for
MaxConcurrentWritesis actually0(see #7033). I have not really changed any defaults on this particular device, except for settingmaxFolderConcurrencyto-1, which I always do (the reason explained in https://forum.syncthing.net/t/concurrency/14607).Should I manually change
MaxConcurrentWritesfrom0(set by Syncthing) to2?lib/model: Sanity checks on MaxConcurrentWrites (ref syncthing#7064)
imsodin commentedon Oct 30, 2020
That's indeed bad. For this particular problem the following proposed change will mitigate it, however we should really fix the folder defaults issue in general.
#7069
Yes
lib/config: Sanity checks on MaxConcurrentWrites (ref #7064) (#7069)
Merge branch 'main' into encryption-featureflag
Merge branch 'main' into cdc