From 540dc3eff0cb357769b5faa10bb8464eca984c53 Mon Sep 17 00:00:00 2001 From: Brian O'Neill Date: Thu, 17 Aug 2017 11:44:26 -0700 Subject: [PATCH 1/4] Fix perf issue where main event loop takes 100% of CPU MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- mssqlscripter/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mssqlscripter/main.py b/mssqlscripter/main.py index 333f4f7..7926a99 100644 --- a/mssqlscripter/main.py +++ b/mssqlscripter/main.py @@ -86,8 +86,9 @@ def main(args): scripting_request.execute() while not scripting_request.completed(): + # The sleep prevents burning up the CPU and lets other threads get scheduled. + time.sleep(0.1) response = scripting_request.get_response() - if response: scriptercallbacks.handle_response(response, parameters.DisplayProgress) From 77cf1675de9f9a155342f8f4c5a592f3751a2014 Mon Sep 17 00:00:00 2001 From: Brian O'Neill Date: Thu, 17 Aug 2017 11:58:52 -0700 Subject: [PATCH 2/4] Appease pylint --- mssqlscripter/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mssqlscripter/main.py b/mssqlscripter/main.py index 7926a99..4a0524d 100644 --- a/mssqlscripter/main.py +++ b/mssqlscripter/main.py @@ -87,7 +87,7 @@ def main(args): while not scripting_request.completed(): # The sleep prevents burning up the CPU and lets other threads get scheduled. - time.sleep(0.1) + time.sleep(0.1) response = scripting_request.get_response() if response: scriptercallbacks.handle_response(response, parameters.DisplayProgress) From 3e529cea755af2f3969dfed67d4707fa4ffd1366 Mon Sep 17 00:00:00 2001 From: Brian O'Neill Date: Thu, 17 Aug 2017 12:00:59 -0700 Subject: [PATCH 3/4] VS solution/project tweaks --- sql-xplat-cli.pyproj | 9 +++------ sql-xplat-cli.sln | 7 +++++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sql-xplat-cli.pyproj b/sql-xplat-cli.pyproj index dd14868..d66fda1 100644 --- a/sql-xplat-cli.pyproj +++ b/sql-xplat-cli.pyproj @@ -11,8 +11,6 @@ . {888888a0-9f3d-457c-b088-3a5042f75d52} Standard Python launcher - - -S localhost -d AdventureWorks2014 False False @@ -21,10 +19,11 @@ 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets + + @@ -43,7 +42,6 @@ - @@ -87,6 +85,5 @@ - - + \ No newline at end of file diff --git a/sql-xplat-cli.sln b/sql-xplat-cli.sln index 97bcd3c..7095fd2 100644 --- a/sql-xplat-cli.sln +++ b/sql-xplat-cli.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "sql-xplat-cli", "sql-xplat-cli.pyproj", "{F4BB6290-43F3-4F35-B26E-067C5EF8E64B}" EndProject @@ -17,4 +17,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1A0F24BB-2803-4A8C-9816-CB374FAAC673} + EndGlobalSection EndGlobal From f426c4234b30b5d48b7d6a7833c3dc29be819c31 Mon Sep 17 00:00:00 2001 From: Brian O'Neill Date: Thu, 17 Aug 2017 12:09:33 -0700 Subject: [PATCH 4/4] Add build.py to VS project --- sql-xplat-cli.pyproj | 1 + 1 file changed, 1 insertion(+) diff --git a/sql-xplat-cli.pyproj b/sql-xplat-cli.pyproj index d66fda1..9c31b76 100644 --- a/sql-xplat-cli.pyproj +++ b/sql-xplat-cli.pyproj @@ -48,6 +48,7 @@ +