Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit ae3c60c

Browse files
authored
Fix perf issue where main event loop takes 100% of CPU (#132)
Fix perf issue where main event loop takes 100% of CPU We have a 2 threads: Thread #1 runs in a loop polling the response queue Thread #2 runs in a loop decoding responses from the sqltoolsservice over stdout and posting them to the response queue Since thread #1 doesn't sleep, it's takes 100% CPU. In addition, running python 2.7 on windows, #2 doesn’t preempt the CPU due to #1 taking all of the CPU cycles, so no response is processed. Fix is simple – thread #1 needs to sleep so thread #2 can get scheduled and get it’s work done.
1 parent 24a5dc8 commit ae3c60c

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

mssqlscripter/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ def main(args):
8686
scripting_request.execute()
8787

8888
while not scripting_request.completed():
89+
# The sleep prevents burning up the CPU and lets other threads get scheduled.
90+
time.sleep(0.1)
8991
response = scripting_request.get_response()
90-
9192
if response:
9293
scriptercallbacks.handle_response(response, parameters.DisplayProgress)
9394

sql-xplat-cli.pyproj

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
<SchemaVersion>2.0</SchemaVersion>
66
<ProjectGuid>{f4bb6290-43f3-4f35-b26e-067c5ef8e64b}</ProjectGuid>
77
<ProjectHome />
8-
<StartupFile>build.py</StartupFile>
8+
<StartupFile>mssqlscripter\main.py</StartupFile>
99
<SearchPath>.</SearchPath>
1010
<WorkingDirectory>.</WorkingDirectory>
1111
<OutputPath>.</OutputPath>
1212
<ProjectTypeGuids>{888888a0-9f3d-457c-b088-3a5042f75d52}</ProjectTypeGuids>
1313
<LaunchProvider>Standard Python launcher</LaunchProvider>
14-
<InterpreterId>Global|PythonCore|2.7</InterpreterId>
15-
<CommandLineArguments>
16-
</CommandLineArguments>
14+
<CommandLineArguments>-S localhost -d AdventureWorks2014</CommandLineArguments>
1715
<EnableNativeCodeDebugging>False</EnableNativeCodeDebugging>
1816
<IsWindowsApplication>False</IsWindowsApplication>
1917
</PropertyGroup>
@@ -26,6 +24,7 @@
2624
<Content Include=".gitignore" />
2725
<Content Include="appveyor.yml" />
2826
<Content Include="dev_requirements.txt" />
27+
<Content Include="doc\README.md" />
2928
<Content Include="doc\architecture_guide.md" />
3029
<Content Include="doc\development_guide.md" />
3130
<Content Include="doc\pypi_release_steps.md" />
@@ -49,9 +48,7 @@
4948
<Content Include=".travis.yml" />
5049
</ItemGroup>
5150
<ItemGroup>
52-
<Compile Include="build.py">
53-
<SubType>Code</SubType>
54-
</Compile>
51+
<Compile Include="build.py" />
5552
<Compile Include="dev_setup.py" />
5653
<Compile Include="mssqlscripter\argparser.py" />
5754
<Compile Include="mssqlscripter\jsonrpc\contracts\scriptingservice.py" />
@@ -89,9 +86,5 @@
8986
<Folder Include="mssqltoolsservice\" />
9087
<Folder Include="mssqltoolsservice\mssqltoolsservice\" />
9188
</ItemGroup>
92-
<ItemGroup>
93-
<InterpreterReference Include="Global|PythonCore|2.7" />
94-
<InterpreterReference Include="Global|PythonCore|3.6" />
95-
</ItemGroup>
9689
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
9790
</Project>

sql-xplat-cli.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ Global
1818
HideSolutionNode = FALSE
1919
EndGlobalSection
2020
GlobalSection(ExtensibilityGlobals) = postSolution
21-
SolutionGuid = {1DD06426-BEB7-4299-B45E-04535B761301}
21+
SolutionGuid = {1A0F24BB-2803-4A8C-9816-CB374FAAC673}
2222
EndGlobalSection
2323
EndGlobal

0 commit comments

Comments
 (0)