Tuning machine.config

Discussion in 'Scripting' started by haber123, Aug 3, 2019.

  1. haber123

    haber123 MDL Junior Member

    Nov 5, 2009
    57
    21
    0
    Microsoft .Net tuning increases performance of .Net applications. The defualt windows settings are way too low for modern PC's and programs. My question is: are there any programs that let you modify the machine.config file to insert the changes into the correct locations?

    <configuration>
    <system.Net>
    <connectionManagement>
    <add address="*" maxconnection="24" />
    </connectionManagement>
    </system.Net>
    <system.web>
    <processModel autoConfig="true"
    maxWorkerThreads = "100"
    maxIoThreads = "100"
    minWorkerThreads = "50"
    minIoThreads = "50"
    />
    </system.web>
    </configuration>

    Any help on this would be greatly appreciated.
     
  2. haber123

    haber123 MDL Junior Member

    Nov 5, 2009
    57
    21
    0
    This significantly improves workstation performance. Anyone know of a program to make these changes rather than editing directly?


    from: docs.frozenmountain.com/websync4/index.html#class=websync-performance-tuning

    machine.config Settings

    Apply these settings to the following four locations:

    • %WINDOWS%\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config
    • %WINDOWS%\Microsoft.NET\Framework\v4.0.30319\CONFIG\machine.config
    • %WINDOWS%\Microsoft.NET\Framework64\v2.0.50727\CONFIG\machine.config
    • %WINDOWS%\Microsoft.NET\Framework64\v4.0.30319\CONFIG\machine.config
    Element Attribute Name Attribute Value
    system.web/processModel autoConfig false
    system.web/processModel maxWorkerThreads 100
    system.web/processModel maxIoThreads 100
    system.web/processModel requestQueueLimit 100000
    applicationHost.config Settings
    Apply these settings to %WINDOWS%\System32\inetsrv\config\applicationHost.config:

    Element Attribute Name Attribute Value
    system.webServer/serverRuntime appConcurrentRequestLimit 100000
     
  3. rayleigh_otter

    rayleigh_otter MDL Expert

    Aug 8, 2018
    1,121
    933
    60
    can that lot be applied with a bat or cmd file?
     
  4. Thomas Dubreuil

    Thomas Dubreuil MDL Senior Member

    Aug 29, 2017
    363
    620
    10
    #4 Thomas Dubreuil, Aug 4, 2019
    Last edited: Aug 4, 2019
    It's an easy task in Notepad++...I've even done custom notepad++ context menu entries for "txt files" types like .config here:
    https://github.com/Thdub/Personalize_Next_Gen/blob/master/CUSTOMIZE/05_Applications_Context_Menu/02_Notepad++ContextMenu.reg

    Obviously :)
    I'm not a pro in regex but think this can easily be done with Jrepl, like
    Code:
    @echo off
    REM Real path to restore after testing
    REM set "Net_path=C:\Windows\Microsoft.NET"
    REM Test paths
    set "Net_path=C:\Users\%UserName%\Desktop\New Folder\Microsoft.NET"
    set "Jrepl_path=C:\Users\%UserName%\Desktop\JREPL.bat"
    REM JREPL stuff
    set "start_line=<system.web>"
    set "second_line=<processModel autoConfig="
    set "repl_1="false""
    set "repl_2=maxWorkerThreads="100""
    set "repl_3=maxIoThreads="100""
    set "repl_4=minWorkerThreads="50""
    set "repl_5=minIoThreads="50"/>"
    set "replace_by=%repl_1% %repl_2% %repl_3% %repl_4% %repl_5%"
    REM Escaping quotes with \q for JRepl (and in this case do not forget to add /x )
    set "replace_by=%replace_by:"=\q%"
    REM Jrepl COMMAND
    "%Jrepl_path%" "%start_line%\r\n(.*)%second_line%\q(.*)\r\n" "%start_line%\r\n$1%second_line%%replace_by%\r\n" /x /m /f "%Net_path%\Framework64\v4.0.30319\CONFIG\machine.config" /o -
    exit /b
    
    I've used \r\n for "end of line symbol" (CR\LF) after the first line,
    then wildcard (.*) before second line, replaced by itself ($1), to preserve space and alignment,
    then another wildcard (.*) at the end just in case value is set to "true" or "false"...
    might be simpler but then I'm far from a pro in regex, gives me headache :D

    ps Download Jrepl is here: https://www.dostips.com/forum/viewtopic.php?t=6044

    edit: this should work too and for all files at once...
    Code:
    @echo off
    set "Jrepl_path=C:\Users\%UserName%\Desktop\JREPL.bat"
    set "windir=C:\Windows"
    set "Net_path=%windir%\Microsoft.NET\Framework"
    set "config_files=%Net_path%\v2.0.50727\CONFIG\machine.config,%Net_path%\v4.0.30319\CONFIG\machine.config,%Net_path%64\v2.0.50727\CONFIG\machine.config,%Net_path%64\v4.0.30319\CONFIG\machine.config"
    set "start_line=<system.web>"
    set "second_line=<processModel autoConfig="
    set "repl_1="false""
    set "repl_2=maxWorkerThreads="100""
    set "repl_3=maxIoThreads="100""
    set "repl_4=minWorkerThreads="50""
    set "repl_5=minIoThreads="50"/>"
    set "replace_by=%second_line%%repl_1% %repl_2% %repl_3% %repl_4% %repl_5%"
    set "replace_by=%replace_by:"=\q%"
    for %%g in (%config_files%) do (
       "%Jrepl_path%" "%start_line%\r\n(.*)%second_line%\q(.*)\r\n" "%start_line%\r\n$1%replace_by%\r\n" /x /m /f "%%g" /o -
    )
    exit /b
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. haber123

    haber123 MDL Junior Member

    Nov 5, 2009
    57
    21
    0
    #5 haber123, Aug 4, 2019
    Last edited: Aug 4, 2019
    (OP)
    But there are other files that if the same variable is defined over ride the machine.config; the system.config, and aspnet.config are two. Plus there are custom app sections that can over ride machine.config values as well. Plus there are various editions of .Net with own configurations,, ie .net 2 and .net 4. I was thinking there should be a program that would show the current state, allow for tweaked values. What a program to make. In my experimenting, programs are much more responsive and run much faster. A tweaked older PC will out perform a newer un-tweaked PC. And yet no one has made a .Net tweaker? Maybe a good MDL project.

    My interests in tuning are for WCF applications.

    PS Thomas Dubreuil nice scripts.
     
  6. rayleigh_otter

    rayleigh_otter MDL Expert

    Aug 8, 2018
    1,121
    933
    60
  7. Thomas Dubreuil

    Thomas Dubreuil MDL Senior Member

    Aug 29, 2017
    363
    620
    10
    #7 Thomas Dubreuil, Aug 4, 2019
    Last edited: Aug 5, 2019
    I think it's not necessary to make an app for that...because tweaking knobs manually in an app would be slower than running a fast script like this one...
    You could put that script to run at startup either via gpo or via taskscheduler, or make a shortcut to the script for your app that needs optimization, launching app at the end of ther script (= adding start "YOURAPP" at the end before exit /b )
    Here's full script you need:
    Code:
    @echo off
    %windir%\system32\reg.exe query "HKU\S-1-5-19" 1>nul 2>nul || goto :No_Admin
    set "Jrepl_path=C:\Users\%UserName%\Desktop\JREPL.bat"
    set "Net_path=C:\Windows\Microsoft.NET\Framework"
    set "config_files=%Net_path%\v2.0.50727\CONFIG\machine.config,%Net_path%\v4.0.30319\CONFIG\machine.config,%Net_path%64\v2.0.50727\CONFIG\machine.config,%Net_path%64\v4.0.30319\CONFIG\machine.config"
    set "start_line=<system.web>"
    set "second_line=<processModel autoConfig="
    set "repl_1="false" maxWorkerThreads="100" maxIoThreads="100" minWorkerThreads="50" minIoThreads="50"/>"
    set "replace_by=%second_line%%repl_1%"
    set /a "n=0"
    echo Checking files...
    setlocal EnableDelayedExpansion
    for %%g in (%config_files%) do ( for /f "tokens=1,2,3,4,5,6" %%a in (%%g) do ( set "Line_to_Tweak=%%a %%b %%c %%d %%e %%f" & for /f "tokens=*" %%S in ("!Line_to_Tweak!") do (
       if "%%S"=="!replace_by!" ( echo   %%g is already tweaked, action not needed.)
       if "%%S"=="!second_line!"true"/>    " ( echo   %%g needs tweaking.&set /a "n+=1" &set "file_to_tweak_!n!=%%~dpnxg" )
       if "%%S"=="!second_line!"false"/>    " ( echo   %%g needs tweaking.&set /a "n+=1" &set "file_to_tweak_!n!=%%~dpnxg" )
    )))
    if "%n%"=="0" ( goto :Reg_check )
    if "%n%"=="1" (
       <nul set /p DummyName=Tweaking 1 file...) else (
       <nul set /p DummyName=Tweaking %n% files...)
    set "replace_by=%replace_by:"=\q%"
    :loop_it
    if "%n%"=="0" ( goto :Tweaking_Done )
    set "Jrepl_file=!file_to_tweak_%n%!"
    call "%Jrepl_path%" "%start_line%\r\n(.*)%second_line%\q(.*)\r\n" "%start_line%\r\n$1%replace_by%\r\n" /x /m /f "%Jrepl_file%" /o -
    set /a "n-=1"
    goto :loop_it
    :Tweaking_Done
    echo Done.
    :Reg_check
    echo: & echo Setting registry keys...
    reg add "HKLM\System\CurrentControlSet\Services\TcpIp\Parameters" /v "TcpTimedWaitDelay" /t REG_DWORD /d "30" /f >NUL 2>&1
    reg add "HKLM\System\CurrentControlSet\Services\HTTP\Parameters" /v "MaxConnections" /t REG_DWORD /d "100000" /f >NUL 2>&1
    reg add "HKLM\SOFTWARE\Microsoft\ASP.NET\2.0.50727.0" /v "MaxConcurrentRequestsPerCPU" /t REG_DWORD /d 0 /f >NUL 2>&1
    reg add "HKLM\SOFTWARE\Microsoft\ASP.NET\2.0.50727.0" /v "MaxConcurrentThreadsPerCPU" /t REG_DWORD /d 0 /f >NUL 2>&1
    reg add "HKLM\SOFTWARE\Microsoft\ASP.NET\4.0.30319.0" /v "MaxConcurrentRequestsPerCPU" /t REG_DWORD /d 0 /f >NUL 2>&1
    reg add "HKLM\SOFTWARE\Microsoft\ASP.NET\4.0.30319.0" /v "MaxConcurrentThreadsPerCPU" /t REG_DWORD /d 0 /f >NUL 2>&1
    echo: & goto :Exit_stuff
    :No_Admin
    echo You must have administrator rights to run this script.
    :Exit_stuff
    <nul set /p DummyName=Press any key to exit...
    pause >nul
    exit /b
    Then you'll need edit the script to change Jrepl path with your own (I just had put on desktop to test the script) and if you want to launch an app with these optimizations, let's say firefox, just replace last echo: line with
    cd /d "‪C:\Program Files\Mozilla Firefox"
    start firefox.exe
    exit /b

    You could also remove every echo command, they are just informative...making script even more compact, and then launch your shortcut minimized, where echo are useless.

    Finally if you need more path/files, just add the paths separated with a comma inside "config_files" variable.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. haber123

    haber123 MDL Junior Member

    Nov 5, 2009
    57
    21
    0
    Thomas Dubreuil Wonderful script. Where did you learn variables like that? I am impressed.
     
  9. Thomas Dubreuil

    Thomas Dubreuil MDL Senior Member

    Aug 29, 2017
    363
    620
    10
    hehe I'm just a beginner :) wanted to make my own optimization script for work and it was so deep at the end that I encountered almost all kind of situations.
    Learning a lot from the masters here like abbodi1406, BAU, etc....impressive skills! and google or ask when I'm stuck to find appropriate answer.
    And also from many tries and time spent on it...few monthes ago it was all alien language for me, now I almost understand what I do :)

    I"m making a version of it for my optimization script with an additional backup and reset/restore initial values from backup function
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...