{"id":2219,"date":"2018-09-09T16:43:44","date_gmt":"2018-09-09T16:43:44","guid":{"rendered":"http:\/\/nenadnoveljic.com\/blog\/?p=2219"},"modified":"2018-09-14T07:45:30","modified_gmt":"2018-09-14T07:45:30","slug":"tcp-storm-in-sql-server","status":"publish","type":"post","link":"https:\/\/nenadnoveljic.com\/blog\/tcp-storm-in-sql-server\/","title":{"rendered":"TCP Storm in SQL Server"},"content":{"rendered":"<p>In this blog post I&#8217;ll be demonstrating how a TSQL loop can cause a massive amount of TCP packets going from SQL Server to client. I used Wireshark to record the traffic and then the Tabular Data Stream (TDS) dissector for reconstructing the TDS stream. <\/p>\n<p>First, let&#8217;s examine the exchange between client and server in a normal case. <\/p>\n<p>The following loop has a 1 second delay:<\/p>\n<pre><code>WHILE 1 = 1\r\nBEGIN\r\n  IF 1 = 0 SELECT 1\r\n  WAITFOR DELAY '00:00:01'\r\nEND;<\/code><\/pre>\n<p>And its execution will produce the following messages:<\/p>\n<pre><code>Source      Destination Protocol Length Info\r\nclient      server      TDS      112    SQL batch\r\nserver      client      TDS      91     Response\r\nclient      server      TDS      234    SQL batch\r\nserver      client      TCP      54     49501 \u2192 58205 [ACK] Seq=38 Ack=239 Win=8207 Len=0<\/code><\/pre>\n<p>As you can see, there were two batches sent from the client. One is the implicit &#8220;select from @@SPID&#8221; command. The other is our endless loop. After receiving the SQL batch, the server sent a zero size ACK to the client. There weren&#8217;t any other messages while the loop was running.<\/p>\n<p>But something strange happened after removing the delay from the loop:<\/p>\n<pre><code>WHILE 1 = 1\r\nBEGIN\r\n  IF 1 = 0 SELECT 1\r\nEND;<\/code><\/pre>\n<p>After receiving the SQL batch from the client, the SQL Server started sending an &#8220;endless&#8221; byte stream instead of a zero size ACK.<\/p>\n<pre><code>Source      Destination Protocol Length Info\r\nclient      server      TDS      112    SQL batch\r\nserver      client      TDS      107    Response\r\nclient      server      TDS      178    SQL batch\r\n<span style=\"color:red\">server      client      TCP      1514   49501 \u2192 63979 [ACK] Seq=54 Ack=183 Win=8211 Len=1460 [TCP segment of a reassembled PDU]\r\nserver      client      TCP      1514   49501 \u2192 63979 [ACK] Seq=1514 Ack=183 Win=8211 Len=1460 [TCP segment of a reassembled PDU]\r\nserver      client      TDS      1230   Response (Not last buffer)\r\nserver      client      TCP      1514   49501 \u2192 63979 [ACK] Seq=4150 Ack=183 Win=8211 Len=1460 [TCP segment of a reassembled PDU]\r\nserver      client      TCP      1514   49501 \u2192 63979 [ACK] Seq=5610 Ack=183 Win=8211 Len=1460 [TCP segment of a reassembled PDU]\r\nserver      client      TDS      1230   Response (Not last buffer)\r\n...<\/span><\/code><\/pre>\n<p>This anomaly can be reproduced on SQL Server 2014, 2016 and 2017. On SQL Server 2014, it can even cause a serious performance bottleneck when TDS encryption is turned on, because every encrypted message will result in a context switch. Fortunately, there isn&#8217;t such context switching in the later releases. <\/p>\n<p>By the way, I elaborated on this in <a href=\"http:\/\/nenadnoveljic.com\/blog\/excessive-context-switching-due-to-tds-encryption\/\">my previous blog post<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Beware of TCP storms in SQL Server, especially in SQL Server 2014 where they can cause a serious performance problem. <a href=\"https:\/\/nenadnoveljic.com\/blog\/tcp-storm-in-sql-server\/\" class=\"more-link\">Continue Reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[17,23],"tags":[],"class_list":["post-2219","post","type-post","status-publish","format-standard","hentry","category-sql-server","category-tcp-ip"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>TCP Storm in SQL Server - All-round Database Topics<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nenadnoveljic.com\/blog\/tcp-storm-in-sql-server\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"TCP Storm in SQL Server - All-round Database Topics\" \/>\n<meta property=\"og:description\" content=\"Beware of TCP storms in SQL Server, especially in SQL Server 2014 where they can cause a serious performance problem. Continue Reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nenadnoveljic.com\/blog\/tcp-storm-in-sql-server\/\" \/>\n<meta property=\"og:site_name\" content=\"All-round Database Topics\" \/>\n<meta property=\"article:published_time\" content=\"2018-09-09T16:43:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-09-14T07:45:30+00:00\" \/>\n<meta name=\"author\" content=\"Nenad Noveljic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@NenadNoveljic\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nenad Noveljic\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/tcp-storm-in-sql-server\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/tcp-storm-in-sql-server\\\/\"},\"author\":{\"name\":\"Nenad Noveljic\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\"},\"headline\":\"TCP Storm in SQL Server\",\"datePublished\":\"2018-09-09T16:43:44+00:00\",\"dateModified\":\"2018-09-14T07:45:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/tcp-storm-in-sql-server\\\/\"},\"wordCount\":225,\"commentCount\":2,\"articleSection\":[\"SQL Server\",\"TCP\\\/IP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/tcp-storm-in-sql-server\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/tcp-storm-in-sql-server\\\/\",\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/tcp-storm-in-sql-server\\\/\",\"name\":\"TCP Storm in SQL Server - All-round Database Topics\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#website\"},\"datePublished\":\"2018-09-09T16:43:44+00:00\",\"dateModified\":\"2018-09-14T07:45:30+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/tcp-storm-in-sql-server\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/tcp-storm-in-sql-server\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/tcp-storm-in-sql-server\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"TCP Storm in SQL Server\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/\",\"name\":\"All-round Database Topics\",\"description\":\"Nenad Noveljic\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\",\"name\":\"Nenad Noveljic\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"caption\":\"Nenad Noveljic\"},\"sameAs\":[\"nenad-noveljic-9b746a6\",\"https:\\\/\\\/x.com\\\/NenadNoveljic\"],\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/author\\\/nenad\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"TCP Storm in SQL Server - All-round Database Topics","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/nenadnoveljic.com\/blog\/tcp-storm-in-sql-server\/","og_locale":"en_US","og_type":"article","og_title":"TCP Storm in SQL Server - All-round Database Topics","og_description":"Beware of TCP storms in SQL Server, especially in SQL Server 2014 where they can cause a serious performance problem. Continue Reading &rarr;","og_url":"https:\/\/nenadnoveljic.com\/blog\/tcp-storm-in-sql-server\/","og_site_name":"All-round Database Topics","article_published_time":"2018-09-09T16:43:44+00:00","article_modified_time":"2018-09-14T07:45:30+00:00","author":"Nenad Noveljic","twitter_card":"summary_large_image","twitter_creator":"@NenadNoveljic","twitter_misc":{"Written by":"Nenad Noveljic","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nenadnoveljic.com\/blog\/tcp-storm-in-sql-server\/#article","isPartOf":{"@id":"https:\/\/nenadnoveljic.com\/blog\/tcp-storm-in-sql-server\/"},"author":{"name":"Nenad Noveljic","@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa"},"headline":"TCP Storm in SQL Server","datePublished":"2018-09-09T16:43:44+00:00","dateModified":"2018-09-14T07:45:30+00:00","mainEntityOfPage":{"@id":"https:\/\/nenadnoveljic.com\/blog\/tcp-storm-in-sql-server\/"},"wordCount":225,"commentCount":2,"articleSection":["SQL Server","TCP\/IP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nenadnoveljic.com\/blog\/tcp-storm-in-sql-server\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nenadnoveljic.com\/blog\/tcp-storm-in-sql-server\/","url":"https:\/\/nenadnoveljic.com\/blog\/tcp-storm-in-sql-server\/","name":"TCP Storm in SQL Server - All-round Database Topics","isPartOf":{"@id":"https:\/\/nenadnoveljic.com\/blog\/#website"},"datePublished":"2018-09-09T16:43:44+00:00","dateModified":"2018-09-14T07:45:30+00:00","author":{"@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa"},"breadcrumb":{"@id":"https:\/\/nenadnoveljic.com\/blog\/tcp-storm-in-sql-server\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nenadnoveljic.com\/blog\/tcp-storm-in-sql-server\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/nenadnoveljic.com\/blog\/tcp-storm-in-sql-server\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/nenadnoveljic.com\/blog\/"},{"@type":"ListItem","position":2,"name":"TCP Storm in SQL Server"}]},{"@type":"WebSite","@id":"https:\/\/nenadnoveljic.com\/blog\/#website","url":"https:\/\/nenadnoveljic.com\/blog\/","name":"All-round Database Topics","description":"Nenad Noveljic","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nenadnoveljic.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa","name":"Nenad Noveljic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","caption":"Nenad Noveljic"},"sameAs":["nenad-noveljic-9b746a6","https:\/\/x.com\/NenadNoveljic"],"url":"https:\/\/nenadnoveljic.com\/blog\/author\/nenad\/"}]}},"_links":{"self":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/2219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/comments?post=2219"}],"version-history":[{"count":1,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/2219\/revisions"}],"predecessor-version":[{"id":2229,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/2219\/revisions\/2229"}],"wp:attachment":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/media?parent=2219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/categories?post=2219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/tags?post=2219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}