Measuring latency of a long-distance SQL connection












2















We have written a simple "client" app for a customer that connects to their SQLServer database, runs about 360 queries against a "property", and returns that data as a .Net object we call a "cProp".



The queries vary in complexity, but the very longest take perhaps 400ms. When we recently ran it for 60 properties, the entire run took about 3 minutes. The customer has decided to move their database to a remote server with 65ms between us. As a result, the same query required 51 minutes.



Now I'm 99% sure the problem is row retrieval, but I need to prove that. The DBA ran a trace on the process, but having never used it before, I was dismayed to find out how little information it contained. What I did see is that it took just under 4 minutes of server time. This reinforces my belief that the problem is in the row retrieval.



But how do I measure that? The trace returns nothing about the number of rows or total data size - am I doing it wrong? I also know that batching happens outside the server, so how do we even find out what's going on there? Generally speaking, how does one debug issues that are taking place "outside the server" so to speak.










share|improve this question





























    2















    We have written a simple "client" app for a customer that connects to their SQLServer database, runs about 360 queries against a "property", and returns that data as a .Net object we call a "cProp".



    The queries vary in complexity, but the very longest take perhaps 400ms. When we recently ran it for 60 properties, the entire run took about 3 minutes. The customer has decided to move their database to a remote server with 65ms between us. As a result, the same query required 51 minutes.



    Now I'm 99% sure the problem is row retrieval, but I need to prove that. The DBA ran a trace on the process, but having never used it before, I was dismayed to find out how little information it contained. What I did see is that it took just under 4 minutes of server time. This reinforces my belief that the problem is in the row retrieval.



    But how do I measure that? The trace returns nothing about the number of rows or total data size - am I doing it wrong? I also know that batching happens outside the server, so how do we even find out what's going on there? Generally speaking, how does one debug issues that are taking place "outside the server" so to speak.










    share|improve this question



























      2












      2








      2


      1






      We have written a simple "client" app for a customer that connects to their SQLServer database, runs about 360 queries against a "property", and returns that data as a .Net object we call a "cProp".



      The queries vary in complexity, but the very longest take perhaps 400ms. When we recently ran it for 60 properties, the entire run took about 3 minutes. The customer has decided to move their database to a remote server with 65ms between us. As a result, the same query required 51 minutes.



      Now I'm 99% sure the problem is row retrieval, but I need to prove that. The DBA ran a trace on the process, but having never used it before, I was dismayed to find out how little information it contained. What I did see is that it took just under 4 minutes of server time. This reinforces my belief that the problem is in the row retrieval.



      But how do I measure that? The trace returns nothing about the number of rows or total data size - am I doing it wrong? I also know that batching happens outside the server, so how do we even find out what's going on there? Generally speaking, how does one debug issues that are taking place "outside the server" so to speak.










      share|improve this question
















      We have written a simple "client" app for a customer that connects to their SQLServer database, runs about 360 queries against a "property", and returns that data as a .Net object we call a "cProp".



      The queries vary in complexity, but the very longest take perhaps 400ms. When we recently ran it for 60 properties, the entire run took about 3 minutes. The customer has decided to move their database to a remote server with 65ms between us. As a result, the same query required 51 minutes.



      Now I'm 99% sure the problem is row retrieval, but I need to prove that. The DBA ran a trace on the process, but having never used it before, I was dismayed to find out how little information it contained. What I did see is that it took just under 4 minutes of server time. This reinforces my belief that the problem is in the row retrieval.



      But how do I measure that? The trace returns nothing about the number of rows or total data size - am I doing it wrong? I also know that batching happens outside the server, so how do we even find out what's going on there? Generally speaking, how does one debug issues that are taking place "outside the server" so to speak.







      sql-server sql-server-2012 query-performance






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 13 hours ago









      jadarnel27

      4,2671331




      4,2671331










      asked Dec 7 '18 at 21:21









      Maury MarkowitzMaury Markowitz

      1356




      1356






















          2 Answers
          2






          active

          oldest

          votes


















          5














          Just to clarify some math here:




          • 360 queries per "property"

          • 60 properties * 360 = 21,600 queries

          • 3 minutes in duration is about 120 queries per second


          So in your best case, you're averaging 120 queries per second throughput.



          After moving the SQL Server to somewhere that has a ping latency of 65ms, you're averaging 7 queries per second.



          Your best bet is to




          • measure wait statistics while this query is running


            • If you don't have a monitoring tool, a simple way to do this is running sp_BlitzFirst, an open source tool developed by Brent Ozar Unlimited. It'll take a snapshot of your wait stats (among other things), wait 5 seconds, and then take another snapshot, and show you a summary of the biggest issues

            • You can also see the wait stats since the server started using a query like the one in Paul Randal's blog post: Wait statistics, or please tell me where it hurts



          • Once you've got those results, examine the highest wait stats, and use the SQL Skills wait stats library to dig into what they mean


          Based on your description, it's likely that you'll see ASYNC_NETWORK_IO waits. This can indicate slow network transfer. But usually it means that the client application is doing row-by-row processing, and SQL Server is waiting to send rows (when it really wants to fire them over the network as fast as possible).



          On a related note - in general, it would be far more effective to try to pull larger "groups" of data - rather than running 21,000 queries, and thus making 21,000 round trips over the (potentially slow) network. This is called a "chatty" interface or API, and is generally considered to be an anti-pattern.



          Consider that 65ms * 21,600 queries is 1,404,000 ms, AKA over 23 minutes of overhead. That's a big chunk of overheard that could be removed simply by limiting the number of roundtrips.






          share|improve this answer

































            0














            Another approach to test how long a query takes to retrun from sql server is to use Test-DbaNetworkLatency.



            e.g.




            Test-DbaNetworkLatency -SqlInstance sqlserver2014a, sqlcluster, sqlserver -Query "select top 10 * from otherdb.dbo.table" -Count 10




            Tests the execution results return of "select top 10 * from otherdb.dbo.table" 10 times on sqlserver2014a, sqlcluster, and sqlserver using Windows credentials. You can use -sqlCredential to pass sql creds to above command.



            Typical output (minus server name would be as below):



            >



            ExecutionCount     : 10
            Total : 340.77 ms
            Average : 34.08 ms
            ExecuteOnlyTotal : 246.72 ms
            ExecuteOnlyAverage : 24.67 ms
            NetworkOnlyTotal : 94.05 ms





            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "182"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f224444%2fmeasuring-latency-of-a-long-distance-sql-connection%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              5














              Just to clarify some math here:




              • 360 queries per "property"

              • 60 properties * 360 = 21,600 queries

              • 3 minutes in duration is about 120 queries per second


              So in your best case, you're averaging 120 queries per second throughput.



              After moving the SQL Server to somewhere that has a ping latency of 65ms, you're averaging 7 queries per second.



              Your best bet is to




              • measure wait statistics while this query is running


                • If you don't have a monitoring tool, a simple way to do this is running sp_BlitzFirst, an open source tool developed by Brent Ozar Unlimited. It'll take a snapshot of your wait stats (among other things), wait 5 seconds, and then take another snapshot, and show you a summary of the biggest issues

                • You can also see the wait stats since the server started using a query like the one in Paul Randal's blog post: Wait statistics, or please tell me where it hurts



              • Once you've got those results, examine the highest wait stats, and use the SQL Skills wait stats library to dig into what they mean


              Based on your description, it's likely that you'll see ASYNC_NETWORK_IO waits. This can indicate slow network transfer. But usually it means that the client application is doing row-by-row processing, and SQL Server is waiting to send rows (when it really wants to fire them over the network as fast as possible).



              On a related note - in general, it would be far more effective to try to pull larger "groups" of data - rather than running 21,000 queries, and thus making 21,000 round trips over the (potentially slow) network. This is called a "chatty" interface or API, and is generally considered to be an anti-pattern.



              Consider that 65ms * 21,600 queries is 1,404,000 ms, AKA over 23 minutes of overhead. That's a big chunk of overheard that could be removed simply by limiting the number of roundtrips.






              share|improve this answer






























                5














                Just to clarify some math here:




                • 360 queries per "property"

                • 60 properties * 360 = 21,600 queries

                • 3 minutes in duration is about 120 queries per second


                So in your best case, you're averaging 120 queries per second throughput.



                After moving the SQL Server to somewhere that has a ping latency of 65ms, you're averaging 7 queries per second.



                Your best bet is to




                • measure wait statistics while this query is running


                  • If you don't have a monitoring tool, a simple way to do this is running sp_BlitzFirst, an open source tool developed by Brent Ozar Unlimited. It'll take a snapshot of your wait stats (among other things), wait 5 seconds, and then take another snapshot, and show you a summary of the biggest issues

                  • You can also see the wait stats since the server started using a query like the one in Paul Randal's blog post: Wait statistics, or please tell me where it hurts



                • Once you've got those results, examine the highest wait stats, and use the SQL Skills wait stats library to dig into what they mean


                Based on your description, it's likely that you'll see ASYNC_NETWORK_IO waits. This can indicate slow network transfer. But usually it means that the client application is doing row-by-row processing, and SQL Server is waiting to send rows (when it really wants to fire them over the network as fast as possible).



                On a related note - in general, it would be far more effective to try to pull larger "groups" of data - rather than running 21,000 queries, and thus making 21,000 round trips over the (potentially slow) network. This is called a "chatty" interface or API, and is generally considered to be an anti-pattern.



                Consider that 65ms * 21,600 queries is 1,404,000 ms, AKA over 23 minutes of overhead. That's a big chunk of overheard that could be removed simply by limiting the number of roundtrips.






                share|improve this answer




























                  5












                  5








                  5







                  Just to clarify some math here:




                  • 360 queries per "property"

                  • 60 properties * 360 = 21,600 queries

                  • 3 minutes in duration is about 120 queries per second


                  So in your best case, you're averaging 120 queries per second throughput.



                  After moving the SQL Server to somewhere that has a ping latency of 65ms, you're averaging 7 queries per second.



                  Your best bet is to




                  • measure wait statistics while this query is running


                    • If you don't have a monitoring tool, a simple way to do this is running sp_BlitzFirst, an open source tool developed by Brent Ozar Unlimited. It'll take a snapshot of your wait stats (among other things), wait 5 seconds, and then take another snapshot, and show you a summary of the biggest issues

                    • You can also see the wait stats since the server started using a query like the one in Paul Randal's blog post: Wait statistics, or please tell me where it hurts



                  • Once you've got those results, examine the highest wait stats, and use the SQL Skills wait stats library to dig into what they mean


                  Based on your description, it's likely that you'll see ASYNC_NETWORK_IO waits. This can indicate slow network transfer. But usually it means that the client application is doing row-by-row processing, and SQL Server is waiting to send rows (when it really wants to fire them over the network as fast as possible).



                  On a related note - in general, it would be far more effective to try to pull larger "groups" of data - rather than running 21,000 queries, and thus making 21,000 round trips over the (potentially slow) network. This is called a "chatty" interface or API, and is generally considered to be an anti-pattern.



                  Consider that 65ms * 21,600 queries is 1,404,000 ms, AKA over 23 minutes of overhead. That's a big chunk of overheard that could be removed simply by limiting the number of roundtrips.






                  share|improve this answer















                  Just to clarify some math here:




                  • 360 queries per "property"

                  • 60 properties * 360 = 21,600 queries

                  • 3 minutes in duration is about 120 queries per second


                  So in your best case, you're averaging 120 queries per second throughput.



                  After moving the SQL Server to somewhere that has a ping latency of 65ms, you're averaging 7 queries per second.



                  Your best bet is to




                  • measure wait statistics while this query is running


                    • If you don't have a monitoring tool, a simple way to do this is running sp_BlitzFirst, an open source tool developed by Brent Ozar Unlimited. It'll take a snapshot of your wait stats (among other things), wait 5 seconds, and then take another snapshot, and show you a summary of the biggest issues

                    • You can also see the wait stats since the server started using a query like the one in Paul Randal's blog post: Wait statistics, or please tell me where it hurts



                  • Once you've got those results, examine the highest wait stats, and use the SQL Skills wait stats library to dig into what they mean


                  Based on your description, it's likely that you'll see ASYNC_NETWORK_IO waits. This can indicate slow network transfer. But usually it means that the client application is doing row-by-row processing, and SQL Server is waiting to send rows (when it really wants to fire them over the network as fast as possible).



                  On a related note - in general, it would be far more effective to try to pull larger "groups" of data - rather than running 21,000 queries, and thus making 21,000 round trips over the (potentially slow) network. This is called a "chatty" interface or API, and is generally considered to be an anti-pattern.



                  Consider that 65ms * 21,600 queries is 1,404,000 ms, AKA over 23 minutes of overhead. That's a big chunk of overheard that could be removed simply by limiting the number of roundtrips.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 10 '18 at 13:45

























                  answered Dec 8 '18 at 4:51









                  jadarnel27jadarnel27

                  4,2671331




                  4,2671331

























                      0














                      Another approach to test how long a query takes to retrun from sql server is to use Test-DbaNetworkLatency.



                      e.g.




                      Test-DbaNetworkLatency -SqlInstance sqlserver2014a, sqlcluster, sqlserver -Query "select top 10 * from otherdb.dbo.table" -Count 10




                      Tests the execution results return of "select top 10 * from otherdb.dbo.table" 10 times on sqlserver2014a, sqlcluster, and sqlserver using Windows credentials. You can use -sqlCredential to pass sql creds to above command.



                      Typical output (minus server name would be as below):



                      >



                      ExecutionCount     : 10
                      Total : 340.77 ms
                      Average : 34.08 ms
                      ExecuteOnlyTotal : 246.72 ms
                      ExecuteOnlyAverage : 24.67 ms
                      NetworkOnlyTotal : 94.05 ms





                      share|improve this answer




























                        0














                        Another approach to test how long a query takes to retrun from sql server is to use Test-DbaNetworkLatency.



                        e.g.




                        Test-DbaNetworkLatency -SqlInstance sqlserver2014a, sqlcluster, sqlserver -Query "select top 10 * from otherdb.dbo.table" -Count 10




                        Tests the execution results return of "select top 10 * from otherdb.dbo.table" 10 times on sqlserver2014a, sqlcluster, and sqlserver using Windows credentials. You can use -sqlCredential to pass sql creds to above command.



                        Typical output (minus server name would be as below):



                        >



                        ExecutionCount     : 10
                        Total : 340.77 ms
                        Average : 34.08 ms
                        ExecuteOnlyTotal : 246.72 ms
                        ExecuteOnlyAverage : 24.67 ms
                        NetworkOnlyTotal : 94.05 ms





                        share|improve this answer


























                          0












                          0








                          0







                          Another approach to test how long a query takes to retrun from sql server is to use Test-DbaNetworkLatency.



                          e.g.




                          Test-DbaNetworkLatency -SqlInstance sqlserver2014a, sqlcluster, sqlserver -Query "select top 10 * from otherdb.dbo.table" -Count 10




                          Tests the execution results return of "select top 10 * from otherdb.dbo.table" 10 times on sqlserver2014a, sqlcluster, and sqlserver using Windows credentials. You can use -sqlCredential to pass sql creds to above command.



                          Typical output (minus server name would be as below):



                          >



                          ExecutionCount     : 10
                          Total : 340.77 ms
                          Average : 34.08 ms
                          ExecuteOnlyTotal : 246.72 ms
                          ExecuteOnlyAverage : 24.67 ms
                          NetworkOnlyTotal : 94.05 ms





                          share|improve this answer













                          Another approach to test how long a query takes to retrun from sql server is to use Test-DbaNetworkLatency.



                          e.g.




                          Test-DbaNetworkLatency -SqlInstance sqlserver2014a, sqlcluster, sqlserver -Query "select top 10 * from otherdb.dbo.table" -Count 10




                          Tests the execution results return of "select top 10 * from otherdb.dbo.table" 10 times on sqlserver2014a, sqlcluster, and sqlserver using Windows credentials. You can use -sqlCredential to pass sql creds to above command.



                          Typical output (minus server name would be as below):



                          >



                          ExecutionCount     : 10
                          Total : 340.77 ms
                          Average : 34.08 ms
                          ExecuteOnlyTotal : 246.72 ms
                          ExecuteOnlyAverage : 24.67 ms
                          NetworkOnlyTotal : 94.05 ms






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 12 hours ago









                          KinKin

                          53.1k480188




                          53.1k480188






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Database Administrators Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f224444%2fmeasuring-latency-of-a-long-distance-sql-connection%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              الفوسفات في المغرب

                              Four equal circles intersect: What is the area of the small shaded portion and its height

                              جامعة ليفربول