[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"academy-blogs-th-1-1-all-golang-websocket-load-stress-testing-k6-guide-all--*":3,"academy-blog-translations-5eetr92m80djrui":79},{"data":4,"page":67,"perPage":67,"totalItems":67,"totalPages":67},[5],{"alt":6,"collectionId":7,"collectionName":8,"content":9,"cover_image":10,"cover_image_path":11,"created":12,"created_by":13,"expand":14,"id":73,"keywords":74,"locale":49,"published_at":75,"scheduled_at":13,"school_blog":71,"short_description":76,"slug":77,"status":69,"title":6,"updated":78,"updated_by":13,"views":72},"Golang The Series EP 134: Load & Stress Testing ทดสอบระบบ WebSocket ให้ถึงขีดจำกัดด้วย k6","sclblg987654321","school_blog_translations","\u003Cp style=\"line-height:1.38;margin-bottom:12pt;margin-top:0pt;\" dir=\"ltr\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">ยินดีต้อนรับชาว Gopher ทุกท่านครับ! หลายคนมักจะมั่นใจว่า \"โค้ดฉันเขียนมาดี Scale ได้แน่นอน\" แต่เชื่อไหมครับว่าในสถานการณ์จริง WebSocket Server มักจะมีปัญหาแปลกๆ โผล่ออกมาเมื่อเจอ Traffic จำนวนมหาศาล เช่น&nbsp;\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Memory Leak\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">,&nbsp;\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>File Descriptors เต็ม\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> หรือ&nbsp;\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Context Switch\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> ที่พุ่งสูงจน CPU ทำงานไม่ทัน\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp style=\"line-height:1.38;margin-bottom:12pt;margin-top:0pt;\" dir=\"ltr\">&nbsp;\u003C\u002Fp>\u003Cp style=\"line-height:1.38;margin-bottom:12pt;margin-top:0pt;\" dir=\"ltr\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">วันนี้เราจะมาสวมบทเป็น \"ผู้ทำลาย\" เพื่อพิสูจน์ว่าระบบที่เราสร้างมาตั้งแต่ EP แรกๆ นั้น จะยังคงยืนหยัดอยู่ได้หรือจะพังทลายเมื่อเจอกับพายุ Traffic ครับ!\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp style=\"line-height:1.38;margin-bottom:0pt;margin-top:0pt;\" dir=\"ltr\">&nbsp;\u003C\u002Fp>\u003Ch2>\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>1. Load, Stress และ Soak Testing: ต่างกันอย่างไร?\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp style=\"line-height:1.38;margin-bottom:6pt;margin-top:0pt;\" dir=\"ltr\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">ก่อนจะเริ่ม \"ถล่ม\" ระบบ เราต้องแยกแยะเป้าหมายให้ชัดเจนครับ:\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fp>\u003Cul style=\"margin-bottom:0;margin-top:0;padding-inline-start:48px;\">\u003Cli style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;font-size:11pt;font-style:normal;font-variant:normal;font-weight:400;list-style-type:disc;text-decoration:none;vertical-align:baseline;white-space:pre;\" dir=\"ltr\" aria-level=\"1\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Load Testing:\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> ทดสอบว่าระบบทำงานได้ตาม \"SLA\" ที่คาดหวังไหม (เช่น รองรับ 10,000 Concurrent Users โดยที่ Latency ยังไม่เกิน 200ms)\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fli>\u003Cli style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;font-size:11pt;font-style:normal;font-variant:normal;font-weight:400;list-style-type:disc;text-decoration:none;vertical-align:baseline;white-space:pre;\" dir=\"ltr\" aria-level=\"1\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Stress Testing:\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> การหา&nbsp;\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>\"จุดแตกหัก\" (Breaking Point)\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> เราจะอัด User เข้าไปเรื่อยๆ จนกว่าระบบจะพัง เพื่อดูว่าส่วนไหนไปก่อนเพื่อน (DB, RAM หรือ Network?) และดูการฟื้นตัว (Self-healing)\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fli>\u003Cli style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;font-size:11pt;font-style:normal;font-variant:normal;font-weight:400;list-style-type:disc;text-decoration:none;vertical-align:baseline;white-space:pre;\" dir=\"ltr\" aria-level=\"1\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Soak Testing (สำคัญมากสำหรับ WebSocket):\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> คือการรัน Load ในระดับคงที่เป็นเวลานาน (เช่น 12-24 ชม.) เพื่อดูว่ามีการสะสมของ Memory (Leak) หรือไม่ เพราะ WebSocket เป็นการเชื่อมต่อที่ค้างไว้นาน ปัญหานี้จึงมักไม่โผล่ในการเทสสั้นๆ\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fli>\u003C\u002Ful>\u003Cp style=\"line-height:1.38;margin-bottom:0pt;margin-top:0pt;\" dir=\"ltr\">&nbsp;\u003C\u002Fp>\u003Ch2>\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>2. ทำไมต้อง k6 ในการทดสอบ WebSocket?\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp style=\"line-height:1.38;margin-bottom:6pt;margin-top:0pt;\" dir=\"ltr\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">แม้จะมีเครื่องมืออย่าง&nbsp;\u003C\u002Fspan>\u003C\u002Fspan>\u003Cspan style=\"background-color:#e9eef6;color:#444746;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">JMeter\u003C\u002Fspan>\u003C\u002Fspan>\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> หรือ&nbsp;\u003C\u002Fspan>\u003C\u002Fspan>\u003Cspan style=\"background-color:#e9eef6;color:#444746;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">Locust\u003C\u002Fspan>\u003C\u002Fspan>\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> แต่สำหรับชาว Go เราแนะนำ&nbsp;\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>k6\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> (โดย Grafana) ด้วยเหตุผลดังนี้:\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fp>\u003Cul style=\"margin-bottom:0;margin-top:0;padding-inline-start:48px;\">\u003Cli style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;font-size:11pt;font-style:normal;font-variant:normal;font-weight:400;list-style-type:disc;text-decoration:none;vertical-align:baseline;white-space:pre;\" dir=\"ltr\" aria-level=\"1\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Go-powered Performance:\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> ตัวเอนจินเขียนด้วย Go ให้ประสิทธิภาพที่สูงมากในการทำ Concurrency\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fli>\u003Cli style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;font-size:11pt;font-style:normal;font-variant:normal;font-weight:400;list-style-type:disc;text-decoration:none;vertical-align:baseline;white-space:pre;\" dir=\"ltr\" aria-level=\"1\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>JavaScript Scripting:\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> เขียนสคริปต์ควบคุม Logic ได้ยืดหยุ่น (เหมือนเขียนโค้ดจริงๆ)\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fli>\u003Cli style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;font-size:11pt;font-style:normal;font-variant:normal;font-weight:400;list-style-type:disc;text-decoration:none;vertical-align:baseline;white-space:pre;\" dir=\"ltr\" aria-level=\"1\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Native WebSocket Support:\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> จัดการ Lifecycle ของ WebSocket (Open, Message, Close) ได้อย่างแม่นยำ\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>\u003Cb data-path-to-node=\"12\" data-index-in-node=\"0\">\u003Cstrong>ตัวอย่างโค้ด Go: Instrumentation &amp; Resource Checking\u003C\u002Fstrong>\u003C\u002Fb>\u003C\u002Fh3>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cresponse-element class=\"\" ng-version=\"0.0.0-PLACEHOLDER\">\u003Ccode-block class=\"ng-tns-c1342159905-107 ng-star-inserted\" _nghost-ng-c1342159905=\"\">\u003Cdiv class=\"code-block ng-tns-c1342159905-107 ng-animate-disabled ng-trigger ng-trigger-codeBlockRevealAnimation\" style=\"display:block;\" _ngcontent-ng-c1342159905=\"\" jslog=\"223238;track:impression,attention;BardVeMetadataKey:[[&quot;r_9a282254c2d93497&quot;,&quot;c_b843516c248d78c8&quot;,null,&quot;rc_6c4f0b8939fdc7ed&quot;,null,null,&quot;th&quot;,null,1,null,null,1,0]]\" data-hveid=\"0\" decode-data-ved=\"1\" data-ved=\"0CAAQhtANahgKEwi-gbqT7duSAxUAAAAAHQAAAAAQiAE\">\u003Cdiv class=\"code-block-decoration header-formatted gds-title-s ng-tns-c1342159905-107 ng-star-inserted\" _ngcontent-ng-c1342159905=\"\">\u003Cspan class=\"ng-tns-c1342159905-107\" _ngcontent-ng-c1342159905=\"\">Go\u003C\u002Fspan>\u003Cdiv class=\"buttons ng-tns-c1342159905-107 ng-star-inserted\" _ngcontent-ng-c1342159905=\"\">\u003Cbutton class=\"mdc-icon-button mat-mdc-icon-button mat-mdc-button-base mat-mdc-tooltip-trigger copy-button ng-tns-c1342159905-107 mat-unthemed ng-star-inserted\" _ngcontent-ng-c1342159905=\"\" aria-label=\"Copy code\" mat-icon-button=\"\" mattooltip=\"Copy code\" mat-ripple-loader-uninitialized=\"\" mat-ripple-loader-class-name=\"mat-mdc-button-ripple\" mat-ripple-loader-centered=\"\" jslog=\"179062;track:generic_click,impression;BardVeMetadataKey:[[&quot;r_9a282254c2d93497&quot;,&quot;c_b843516c248d78c8&quot;,null,&quot;rc_6c4f0b8939fdc7ed&quot;,null,null,&quot;th&quot;,null,1,null,null,1,0]];mutable:true\">\u003C\u002Fbutton>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"formatted-code-block-internal-container ng-tns-c1342159905-107\" _ngcontent-ng-c1342159905=\"\">\u003Cdiv class=\"animated-opacity ng-tns-c1342159905-107\" _ngcontent-ng-c1342159905=\"\">\u003Cpre class=\"ng-tns-c1342159905-107\" _ngcontent-ng-c1342159905=\"\">\u003Ccode class=\"code-container formatted ng-tns-c1342159905-107\" _ngcontent-ng-c1342159905=\"\" role=\"text\" data-test-id=\"code-content\">\u003Cspan class=\"hljs-keyword\">package\u003C\u002Fspan> main\n\n\u003Cspan class=\"hljs-keyword\">import\u003C\u002Fspan> (\n\t\u003Cspan class=\"hljs-string\">\"log\"\u003C\u002Fspan>\n\t\u003Cspan class=\"hljs-string\">\"net\u002Fhttp\"\u003C\u002Fspan>\n\t\u003Cspan class=\"hljs-string\">\"runtime\"\u003C\u002Fspan>\n\t\u003Cspan class=\"hljs-string\">\"syscall\"\u003C\u002Fspan>\n\n\t\u003Cspan class=\"hljs-string\">\"github.com\u002Fprometheus\u002Fclient_golang\u002Fprometheus\"\u003C\u002Fspan>\n\t\u003Cspan class=\"hljs-string\">\"github.com\u002Fprometheus\u002Fclient_golang\u002Fprometheus\u002Fpromauto\"\u003C\u002Fspan>\n\t\u003Cspan class=\"hljs-string\">\"github.com\u002Fprometheus\u002Fclient_golang\u002Fprometheus\u002Fpromhttp\"\u003C\u002Fspan>\n)\n\n\u003Cspan class=\"hljs-keyword\">var\u003C\u002Fspan> (\n\t\u003Cspan class=\"hljs-comment\">\u002F\u002F วัดจำนวน Goroutine ที่รันอยู่จริง\u003C\u002Fspan>\n\tgoroutineGauge = promauto.NewGauge(prometheus.GaugeOpts{\n\t\tName: \u003Cspan class=\"hljs-string\">\"current_goroutines_count\"\u003C\u002Fspan>,\n\t\tHelp: \u003Cspan class=\"hljs-string\">\"The total number of current goroutines\"\u003C\u002Fspan>,\n\t})\n)\n\n\u003Cspan class=\"hljs-function\">\u003Cspan class=\"hljs-keyword\">func\u003C\u002Fspan> \u003Cspan class=\"hljs-title\">main\u003C\u002Fspan>\u003Cspan class=\"hljs-params\">()\u003C\u002Fspan>\u003C\u002Fspan> {\n\t\u003Cspan class=\"hljs-comment\">\u002F\u002F 1. ตรวจสอบขีดจำกัดของระบบ (File Descriptors)\u003C\u002Fspan>\n\t\u003Cspan class=\"hljs-keyword\">var\u003C\u002Fspan> rLimit syscall.Rlimit\n\t\u003Cspan class=\"hljs-keyword\">if\u003C\u002Fspan> err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &amp;rLimit); err == \u003Cspan class=\"hljs-literal\">nil\u003C\u002Fspan> {\n\t\tlog.Printf(\u003Cspan class=\"hljs-string\">\"Current File Descriptor Limit: %d\"\u003C\u002Fspan>, rLimit.Cur)\n\t}\n\n\t\u003Cspan class=\"hljs-comment\">\u002F\u002F 2. เสิร์ฟ Metrics สำหรับ Prometheus\u002FGrafana\u003C\u002Fspan>\n\t\u003Cspan class=\"hljs-keyword\">go\u003C\u002Fspan> \u003Cspan class=\"hljs-function\">\u003Cspan class=\"hljs-keyword\">func\u003C\u002Fspan>\u003Cspan class=\"hljs-params\">()\u003C\u002Fspan>\u003C\u002Fspan> {\n\t\thttp.Handle(\u003Cspan class=\"hljs-string\">\"\u002Fmetrics\"\u003C\u002Fspan>, promhttp.Handler())\n\t\tlog.Println(\u003Cspan class=\"hljs-string\">\"Metrics server started on :2112\"\u003C\u002Fspan>)\n\t\thttp.ListenAndServe(\u003Cspan class=\"hljs-string\">\":2112\"\u003C\u002Fspan>, \u003Cspan class=\"hljs-literal\">nil\u003C\u002Fspan>)\n\t}()\n\n\t\u003Cspan class=\"hljs-comment\">\u002F\u002F 3. จำลองการเก็บสถิติ Goroutine ทุกครั้งที่มีการเชื่อมต่อ (ตัวอย่าง)\u003C\u002Fspan>\n\t\u003Cspan class=\"hljs-keyword\">go\u003C\u002Fspan> \u003Cspan class=\"hljs-function\">\u003Cspan class=\"hljs-keyword\">func\u003C\u002Fspan>\u003Cspan class=\"hljs-params\">()\u003C\u002Fspan>\u003C\u002Fspan> {\n\t\t\u003Cspan class=\"hljs-keyword\">for\u003C\u002Fspan> {\n\t\t\tgoroutineGauge.Set(\u003Cspan class=\"hljs-keyword\">float64\u003C\u002Fspan>(runtime.NumGoroutine()))\n\t\t}\n\t}()\n\n\t\u003Cspan class=\"hljs-comment\">\u002F\u002F รัน WebSocket Server ของคุณที่นี่...\u003C\u002Fspan>\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fcode-block>\u003C\u002Fresponse-element>\u003Cpre>\u003Ccode class=\"language-plaintext\">package main\nimport (\n &nbsp;&nbsp;&nbsp;\"log\"\n &nbsp;&nbsp;&nbsp;\"net\u002Fhttp\"\n &nbsp;&nbsp;&nbsp;\"runtime\"\n &nbsp;&nbsp;&nbsp;\"syscall\"\n &nbsp;&nbsp;&nbsp;\"github.com\u002Fprometheus\u002Fclient_golang\u002Fprometheus\"\n &nbsp;&nbsp;&nbsp;\"github.com\u002Fprometheus\u002Fclient_golang\u002Fprometheus\u002Fpromauto\"\n &nbsp;&nbsp;&nbsp;\"github.com\u002Fprometheus\u002Fclient_golang\u002Fprometheus\u002Fpromhttp\"\n)\nvar (\n &nbsp;&nbsp;&nbsp;\u002F\u002F วัดจำนวน Goroutine ที่รันอยู่จริง\n &nbsp;&nbsp;&nbsp;goroutineGauge = promauto.NewGauge(prometheus.GaugeOpts{\n &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name: \"current_goroutines_count\",\n &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Help: \"The total number of current goroutines\",\n &nbsp;&nbsp;&nbsp;})\n)\nfunc main() {\n &nbsp;&nbsp;&nbsp;\u002F\u002F 1. ตรวจสอบขีดจำกัดของระบบ (File Descriptors)\n &nbsp;&nbsp;&nbsp;var rLimit syscall.Rlimit\n &nbsp;&nbsp;&nbsp;if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &amp;rLimit); err == nil {\n &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.Printf(\"Current File Descriptor Limit: %d\", rLimit.Cur)\n &nbsp;&nbsp;&nbsp;}\n &nbsp;&nbsp;&nbsp;\u002F\u002F 2. เสิร์ฟ Metrics สำหรับ Prometheus\u002FGrafana\n &nbsp;&nbsp;&nbsp;go func() {\n &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http.Handle(\"\u002Fmetrics\", promhttp.Handler())\n &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.Println(\"Metrics server started on :2112\")\n &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http.ListenAndServe(\":2112\", nil)\n &nbsp;&nbsp;&nbsp;}()\n &nbsp;&nbsp;&nbsp;\u002F\u002F 3. จำลองการเก็บสถิติ Goroutine ทุกครั้งที่มีการเชื่อมต่อ (ตัวอย่าง)\n &nbsp;&nbsp;&nbsp;go func() {\n &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for {\n &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;goroutineGauge.Set(float64(runtime.NumGoroutine()))\n &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n &nbsp;&nbsp;&nbsp;}()\n &nbsp;&nbsp;&nbsp;\u002F\u002F รัน WebSocket Server ของคุณที่นี่...\n}\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>3. ออกแบบ Scenario: จำลองพฤติกรรม User จริง\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp style=\"line-height:1.38;margin-bottom:6pt;margin-top:0pt;\" dir=\"ltr\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">การเทส WebSocket ไม่ใช่แค่การจิ้มแล้วจบ (Hit &amp; Run) แต่คือการ&nbsp;\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>\"แช่\"\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> การเชื่อมต่อ สิ่งที่คุณต้องจำลองคือ:\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fp>\u003Col style=\"margin-bottom:0;margin-top:0;padding-inline-start:48px;\">\u003Cli style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;font-size:11pt;font-style:normal;font-variant:normal;font-weight:400;list-style-type:decimal;text-decoration:none;vertical-align:baseline;white-space:pre;\" dir=\"ltr\" aria-level=\"1\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Ramping Up:\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> ค่อยๆ เพิ่ม User เพื่อดูอาการของระบบ (Warm-up)\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fli>\u003Cli style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;font-size:11pt;font-style:normal;font-variant:normal;font-weight:400;list-style-type:decimal;text-decoration:none;vertical-align:baseline;white-space:pre;\" dir=\"ltr\" aria-level=\"1\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Sustained Load:\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> จำลองการส่ง Heartbeat หรือข้อความ Chat เป็นระยะ\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fli>\u003Cli style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;font-size:11pt;font-style:normal;font-variant:normal;font-weight:400;list-style-type:decimal;text-decoration:none;vertical-align:baseline;white-space:pre;\" dir=\"ltr\" aria-level=\"1\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>The Storm:\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> การ Broadcast ข้อความพร้อมกันทุกคน (เช่น Notification ส่งหาทุกคน) เพื่อดูแรงกระแทกที่ Server และ Redis Pub\u002FSub\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fli>\u003C\u002Fol>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>ตัวอย่างสคริปต์ k6 (JavaScript):\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fh3>\u003Cp style=\"line-height:1.38;margin-bottom:12pt;margin-top:0pt;\" dir=\"ltr\">&nbsp;\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext\">JavaScript\nimport ws&nbsp;from&nbsp;'k6\u002Fws';\nimport { check, sleep }&nbsp;from&nbsp;'k6';\n\nexport&nbsp;const options = {\n&nbsp;&nbsp;stages: [\n&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;duration:&nbsp;'2m',&nbsp;target:&nbsp;5000 },&nbsp;&nbsp;\u002F\u002F เพิ่มเป็น 5,000 คนใน 2 นาที\n&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;duration:&nbsp;'5m',&nbsp;target:&nbsp;5000 },&nbsp;&nbsp;\u002F\u002F แช่ไว้ที่ 5,000 คนเพื่อดูความนิ่ง\n&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;duration:&nbsp;'1m',&nbsp;target:&nbsp;0 }, &nbsp; &nbsp;&nbsp;\u002F\u002F ค่อยๆ ระบายออก\n&nbsp;&nbsp;],\n};\n\nexport&nbsp;default&nbsp;function () {\n&nbsp;&nbsp;const url =&nbsp;'ws:\u002F\u002Fyour-api-gateway.com\u002Fws';\n&nbsp;&nbsp;\n&nbsp;&nbsp;const res = ws.connect(url,&nbsp;null,&nbsp;function (socket) {\n&nbsp;&nbsp;&nbsp;&nbsp;socket.on('open', () =&gt; {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u002F\u002F ส่งข้อความแรกเมื่อต่อติด\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;socket.send(JSON.stringify({&nbsp;type:&nbsp;'auth',&nbsp;token:&nbsp;'test-token' }));\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u002F\u002F ส่ง Heartbeat ทุกๆ 30 วินาที\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;socket.setInterval(() =&gt; {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;socket.send(JSON.stringify({&nbsp;type:&nbsp;'ping' }));\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},&nbsp;30000);\n&nbsp;&nbsp;&nbsp;&nbsp;});\n\n&nbsp;&nbsp;&nbsp;&nbsp;socket.on('message', (data) =&gt; {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u002F\u002F ตรวจสอบว่าได้รับข้อความตอบกลับถูกต้องไหม\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;check(data, {&nbsp;'is message ok': (d) =&gt; d.includes('pong') });\n&nbsp;&nbsp;&nbsp;&nbsp;});\n\n&nbsp;&nbsp;&nbsp;&nbsp;\u002F\u002F จำลองการเชื่อมต่อค้างไว้ 60 วินาทีก่อนจะปิด (เพื่อวนรอบใหม่)\n&nbsp;&nbsp;&nbsp;&nbsp;socket.setTimeout(() =&gt; {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;socket.close();\n&nbsp;&nbsp;&nbsp;&nbsp;},&nbsp;60000);\n&nbsp;&nbsp;});\n\n&nbsp;&nbsp;check(res, {&nbsp;'status is 101': (r) =&gt; r &amp;&amp; r.status ===&nbsp;101 });\n}\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp style=\"background-color:#f0f4f9;line-height:1.38;margin-bottom:0pt;margin-top:0pt;padding:0pt 0pt 12pt;\" dir=\"ltr\">&nbsp;\u003C\u002Fp>\u003Ch2>\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>4. ตัวเลขที่ห้ามละสายตา (Key Metrics)\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp style=\"line-height:1.38;margin-bottom:6pt;margin-top:0pt;\" dir=\"ltr\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">ระหว่างที่ k6 กำลังถล่มระบบ ให้คุณเปิด Dashboard (จาก EP 128) และดูสิ่งเหล่านี้:\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fp>\u003Col style=\"margin-bottom:0;margin-top:0;padding-inline-start:48px;\">\u003Cli style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;font-size:11pt;font-style:normal;font-variant:normal;font-weight:400;list-style-type:decimal;text-decoration:none;vertical-align:baseline;white-space:pre;\" dir=\"ltr\" aria-level=\"1\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>File Descriptors (FD):\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> ใน Linux ทุก 1 Connection คือ 1 ไฟล์ เช็คด้วย&nbsp;\u003C\u002Fspan>\u003C\u002Fspan>\u003Cspan style=\"background-color:#e9eef6;color:#444746;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">cat \u002Fproc\u002Fsys\u002Ffs\u002Ffile-max\u003C\u002Fspan>\u003C\u002Fspan>\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> (ถ้า FD เต็ม ระบบจะรับคนเพิ่มไม่ได้ทันที)\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fli>\u003Cli style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;font-size:11pt;font-style:normal;font-variant:normal;font-weight:400;list-style-type:decimal;text-decoration:none;vertical-align:baseline;white-space:pre;\" dir=\"ltr\" aria-level=\"1\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Goroutines Count:\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> จำนวน Goroutine ควรจะสัมพันธ์กับจำนวน User ถ้า User ออกแล้ว Goroutine ไม่ลด แสดงว่ามี&nbsp;\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Goroutine Leak\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fli>\u003Cli style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;font-size:11pt;font-style:normal;font-variant:normal;font-weight:400;list-style-type:decimal;text-decoration:none;vertical-align:baseline;white-space:pre;\" dir=\"ltr\" aria-level=\"1\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Memory Usage (RSS):\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> ดูว่ามีการสะสมของ RAM ไปเรื่อยๆ หรือไม่\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fli>\u003Cli style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;font-size:11pt;font-style:normal;font-variant:normal;font-weight:400;list-style-type:decimal;text-decoration:none;vertical-align:baseline;white-space:pre;\" dir=\"ltr\" aria-level=\"1\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Redis Throughput (จาก EP 130):\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> เช็คว่า Redis รับไหวไหมเมื่อมีการ Broadcast หนักๆ\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fli>\u003C\u002Fol>\u003Cp style=\"line-height:1.38;margin-bottom:0pt;margin-top:0pt;\" dir=\"ltr\">&nbsp;\u003C\u002Fp>\u003Ch2>\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>5. การ \"จูน\" เมื่อระบบถึงขีดจำกัด (Tuning Tips)\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp style=\"line-height:1.38;margin-bottom:6pt;margin-top:0pt;\" dir=\"ltr\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">ถ้าเทสแล้วพัง แก้ตรงไหนก่อน?\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fp>\u003Cul style=\"margin-bottom:0;margin-top:0;padding-inline-start:48px;\">\u003Cli style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;font-size:11pt;font-style:normal;font-variant:normal;font-weight:400;list-style-type:disc;text-decoration:none;vertical-align:baseline;white-space:pre;\" dir=\"ltr\" aria-level=\"1\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>OS Level (ulimit):\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> ปรับค่า&nbsp;\u003C\u002Fspan>\u003C\u002Fspan>\u003Cspan style=\"background-color:#e9eef6;color:#444746;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">nofile\u003C\u002Fspan>\u003C\u002Fspan>\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> ใน&nbsp;\u003C\u002Fspan>\u003C\u002Fspan>\u003Cspan style=\"background-color:#e9eef6;color:#444746;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u002Fetc\u002Fsecurity\u002Flimits.conf\u003C\u002Fspan>\u003C\u002Fspan>\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> ให้สูงขึ้น (เช่น 100,000+) ทั้งฝั่ง Server และฝั่งที่รัน k6\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fli>\u003Cli style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;font-size:11pt;font-style:normal;font-variant:normal;font-weight:400;list-style-type:disc;text-decoration:none;vertical-align:baseline;white-space:pre;\" dir=\"ltr\" aria-level=\"1\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Go GC Tuning:\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> ปรับค่า&nbsp;\u003C\u002Fspan>\u003C\u002Fspan>\u003Cspan style=\"background-color:#e9eef6;color:#444746;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">GOGC\u003C\u002Fspan>\u003C\u002Fspan>\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> หรือใช้&nbsp;\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Memory Ballast\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> เพื่อลดความถี่ในการรัน Garbage Collector เมื่อมี Traffic พุ่งสูง\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fli>\u003Cli style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;font-size:11pt;font-style:normal;font-variant:normal;font-weight:400;list-style-type:disc;text-decoration:none;vertical-align:baseline;white-space:pre;\" dir=\"ltr\" aria-level=\"1\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Buffer Reuse:\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> ตรวจสอบว่าได้ใช้&nbsp;\u003C\u002Fspan>\u003C\u002Fspan>\u003Cspan style=\"background-color:#e9eef6;color:#444746;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">sync.Pool\u003C\u002Fspan>\u003C\u002Fspan>\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> (จาก EP 132) ในจุดที่มีการจอง Memory ซ้ำๆ หรือยัง\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Chr>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>สรุป\u003C\u002Fstrong>\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp style=\"line-height:1.38;margin-bottom:12pt;margin-top:0pt;\" dir=\"ltr\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">การทำ&nbsp;\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>Load &amp; Stress Testing\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> ไม่ใช่แค่การหาว่าระบบ \"รับได้เท่าไหร่\" แต่คือการสร้าง&nbsp;\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>\"ความมั่นใจ\"\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> ว่าเมื่อถึงวันที่มี Traffic ถล่มทลาย ระบบของคุณจะยังคงทำงานได้ตามปกติ หรือถ้าจะพัง คุณจะรู้ล่วงหน้าและมีแผนรับมือ (Failover) ที่เตรียมไว้แล้วครับ\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp style=\"line-height:1.38;margin-bottom:12pt;margin-top:0pt;\" dir=\"ltr\">&nbsp;\u003C\u002Fp>\u003Cp style=\"line-height:1.38;margin-bottom:12pt;margin-top:0pt;\" dir=\"ltr\">\u003Cspan style=\"background-color:transparent;color:#1f1f1f;font-family:Arial,sans-serif;\">\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>ในตอนหน้า (EP 135):\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> เราจะนำระบบที่ผ่านการทดสอบสุดโหดนี้เข้าสู่กระบวนการ&nbsp;\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\">\u003Cstrong>CI\u002FCD Pipeline\u003C\u002Fstrong>\u003C\u002Fspan>\u003Cspan style=\"font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;vertical-align:baseline;white-space:pre-wrap;\"> เพื่อให้การส่งมอบโค้ดเป็นไปอย่างอัตโนมัติและปลอดภัยที่สุด ห้ามพลาดครับ!\u003C\u002Fspan>\u003C\u002Fspan>\u003C\u002Fp>\u003Cp style=\"line-height:1.38;margin-bottom:12pt;margin-top:0pt;\" dir=\"ltr\">&nbsp;\u003C\u002Fp>\u003Cdiv class=\"raw-html-embed\">\u003Cdiv style=\"margin:0 0 6px 0; font-weight:700;\">อ่านบทความ Series อื่นๆ:\u003C\u002Fdiv>\n\u003Cul style=\"list-style:none; padding:0; margin:0; line-height:1.4;\">\n  \u003Cli style=\"margin:0;\">\u003Ca href=\"\u002Fblogs\u002Fcategories\u002FGolang\" title=\"Golang The Series\">Golang The Series\u003C\u002Fa>\u003C\u002Fli>\n  \u003Cli style=\"margin:0;\">\u003Ca href=\"\u002Fblogs\u002Fcategories\u002FJS2GO\" title=\"JS2GO\">JS2GO\u003C\u002Fa>\u003C\u002Fli>\n  \u003Cli style=\"margin:0;\">\u003Ca href=\"\u002Fblogs\u002Fcategories\u002FTailwind%20CSS\" title=\"10 Ep ที่จะให้คุณเป็นมือโปร Tailwind CSS ในชั่วข้ามคืน\">10 Ep ที่จะให้คุณเป็นมือโปร Tailwind CSS ในชั่วข้ามคืน\u003C\u002Fa>\u003C\u002Fli>\n\u003C\u002Ful>\u003C\u002Fdiv>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cdiv class=\"raw-html-embed\">\n  \u003Cp style=\"margin:0 0 6px 0;\">\u003Cstrong>Follow Us:\u003C\u002Fstrong>\u003C\u002Fp>\n  \u003Cul style=\"list-style:none; padding:0; margin:0; line-height: 0.4;\">\n    \u003Cli style=\"display:flex; align-items:center; gap:6px; margin:0;\">\n      \n      \u003Csvg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"#1877F2\" aria-hidden=\"true\">\n        \u003Cpath d=\"M22 12.07C22 6.48 17.52 2 11.93 2S2 6.48 2 12.07c0 5 3.66 9.14 8.44 9.93v-7.02H7.9v-2.91h2.54V9.41c0-2.5 1.49-3.88 3.77-3.88 1.09 0 2.24.2 2.24.2v2.46h-1.26c-1.24 0-1.63.77-1.63 1.56v1.87h2.78l-.44 2.91h-2.34V22c4.78-.79 8.44-4.93 8.44-9.93Z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Ca href=\"https:\u002F\u002Fwww.facebook.com\u002Fsuperdev.academy.th\" target=\"_blank\" rel=\"nofollow noopener\" title=\"Follow Superdev Academy on Facebook\">Facebook: Superdev Academy\u003C\u002Fa>\n    \u003C\u002Fli>\n\n    \u003Cli style=\"display:flex; align-items:center; gap:6px; margin:0;\">\n      \n      \u003Csvg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"#FF0000\" aria-hidden=\"true\">\n        \u003Cpath d=\"M23.5 6.2a3 3 0 0 0-2.1-2.1C19.5 3.5 12 3.5 12 3.5s-7.5 0-9.4.6A3 3 0 0 0 .5 6.2 31.5 31.5 0 0 0 0 12a31.5 31.5 0 0 0 .5 5.8 3 3 0 0 0 2.1 2.1c1.9.6 9.4.6 9.4.6s7.5 0 9.4-.6a3 3 0 0 0 2.1-2.1A31.5 31.5 0 0 0 24 12a31.5 31.5 0 0 0-.5-5.8ZM9.75 15.02V8.98L15.5 12l-5.75 3.02Z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Ca href=\"https:\u002F\u002Fwww.youtube.com\u002F@SuperdevAcademy\" target=\"_blank\" rel=\"nofollow noopener\" title=\"Watch on YouTube\">YouTube: Superdev Academy\u003C\u002Fa>\n    \u003C\u002Fli>\n\n    \u003Cli style=\"display:flex; align-items:center; gap:6px; margin:0;\">\n      \n      \u003Csvg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"#E4405F\" aria-hidden=\"true\">\n        \u003Cpath d=\"M7 2h10a5 5 0 0 1 5 5v10a5 5 0 0 1-5 5H7a5 5 0 0 1-5-5V7a5 5 0 0 1 5-5Zm10 2H7a3 3 0 0 0-3 3v10a3 3 0 0 0 3 3h10a3 3 0 0 0 3-3V7a3 3 0 0 0-3-3Zm-5 3.5A5.5 5.5 0 1 1 6.5 13 5.5 5.5 0 0 1 12 7.5Zm0 2A3.5 3.5 0 1 0 15.5 13 3.5 3.5 0 0 0 12 9.5Zm5.75-2.75a1.25 1.25 0 1 1-1.25 1.25 1.25 1.25 0 0 1 1.25-1.25Z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Ca href=\"https:\u002F\u002Fwww.instagram.com\u002Fsuperdevacademy\u002F?hl=en target=\" _blank\"=\"\" rel=\"nofollow noopener\" title=\"See behind-the-scenes on Instagram\">Instagram: Superdev Academy\u003C\u002Fa>\n    \u003C\u002Fli>\n\n    \u003Cli style=\"display:flex; align-items:center; gap:6px; margin:0;\">\n      \n      \u003Csvg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"#000000\" aria-hidden=\"true\">\n        \u003Cpath d=\"M21 8.12a6.86 6.86 0 0 1-4.8-2V16a6 6 0 1 1-6-6 5.9 5.9 0 0 1 1.63.23V8.05a9.08 9.08 0 0 1-1.63-.15V4.5a6.86 6.86 0 0 0 4.8 2.05V6.5a6.86 6.86 0 0 0 4.8 1.62ZM9.2 12.5A3.5 3.5 0 1 0 12.7 16V9.94a6 6 0 0 1-1.63-.27v3.95a3.5 3.5 0 0 1-1.87 3.17 3.5 3.5 0 0 1-4.78-3.23 3.5 3.5 0 0 1 4.78-3.06Z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Ca href=\"https:\u002F\u002Fwww.tiktok.com\u002F@superdevacademy\" target=\"_blank\" rel=\"nofollow noopener\" title=\"Watch short tips on TikTok\">TikTok: @superdevacademy\u003C\u002Fa>\n    \u003C\u002Fli>\n\n    \u003Cli style=\"display:flex; align-items:center; gap:6px; margin:0;\">\n      \n      \u003Csvg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"#111827\" aria-hidden=\"true\">\n        \u003Cpath d=\"M12 2a10 10 0 1 0 10 10A10.01 10.01 0 0 0 12 2Zm6.93 6h-3.26a15.6 15.6 0 0 0-1.39-3.62A8.03 8.03 0 0 1 18.93 8ZM12 4c.73.93 1.7 2.74 2.2 4H9.8C10.3 6.74 11.27 4.93 12 4ZM8.72 4.38A15.6 15.6 0 0 0 7.32 8H4.07a8.03 8.03 0 0 1 4.65-3.62ZM4.07 16h3.25a15.6 15.6 0 0 0 1.4 3.62A8.03 8.03 0 0 1 4.07 16ZM12 20c-.73-.93-1.7-2.74-2.2-4h4.4C13.7 17.26 12.73 19.07 12 20Zm3.28-.38A15.6 15.6 0 0 0 16.68 16h3.25a8.03 8.03 0 0 1-4.65 3.62ZM20 14h-3.54a13.8 13.8 0 0 1-.26-4H20a7.98 7.98 0 0 1 0 4Zm-12.2 0H4a7.98 7.98 0 0 1 0-4h3.54a13.8 13.8 0 0 1-.26 4Zm2 .5h4.4a17.8 17.8 0 0 1-.72-4.5c0-1.58.25-3.1.72-4.5H9.8a17.8 17.8 0 0 1 .72 4.5c0 1.58-.25 3.1-.72 4.5Z\">\u003C\u002Fpath>\n      \u003C\u002Fsvg>\n      \u003Ca href=\"https:\u002F\u002Fwww.superdevacademy.com\u002F\" target=\"_blank\" rel=\"noopener\" title=\"Visit the official website of Superdev Academy\">Official Website: Superdev Academy.com\u003C\u002Fa>\n    \u003C\u002Fli>\n  \u003C\u002Ful>\n\u003C\u002Fdiv>","cover_image_golang_the_series_ep_134_load_stress_testing_web_sockets_with_k6_xxqje98pwi.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclblg987654321\u002Fw3qd4tw05xso27x\u002Fcover_image_golang_the_series_ep_134_load_stress_testing_web_sockets_with_k6_xxqje98pwi.webp","2026-03-04 08:44:20.622Z","",{"keywords":15,"locale":43,"school_blog":53},[16,23,28,33,38],{"collectionId":17,"collectionName":18,"created":19,"created_by":13,"id":20,"name":21,"updated":22,"updated_by":13},"sclkey987654321","school_keywords","2026-03-04 08:20:14.253Z","ah6lvy4x8qe08l5","Golang","2026-04-10 16:07:26.172Z",{"collectionId":17,"collectionName":18,"created":24,"created_by":13,"id":25,"name":26,"updated":27,"updated_by":13},"2026-03-04 08:34:00.920Z","ecac9y661or1xka","WebSocket","2026-04-10 16:08:05.227Z",{"collectionId":17,"collectionName":18,"created":29,"created_by":13,"id":30,"name":31,"updated":32,"updated_by":13},"2026-03-04 08:44:19.453Z","s7490uhe8oarthf","k6","2026-04-10 16:12:43.471Z",{"collectionId":17,"collectionName":18,"created":34,"created_by":13,"id":35,"name":36,"updated":37,"updated_by":13},"2026-03-04 08:44:19.737Z","wfofysa5fhg0v0p","Load Testing","2026-04-10 16:12:43.560Z",{"collectionId":17,"collectionName":18,"created":39,"created_by":13,"id":40,"name":41,"updated":42,"updated_by":13},"2026-03-04 08:34:00.521Z","44l3qn47xjhwgf8","Stress Testing","2026-04-10 16:08:05.159Z",{"code":44,"collectionId":45,"collectionName":46,"created":47,"flag":48,"id":49,"is_default":50,"label":51,"updated":52},"th","pbc_1989393366","locales","2026-01-22 10:59:55.832Z","twemoji:flag-thailand","s8wri3bt4vgg2ji",true,"Thai","2026-04-10 15:42:46.614Z",{"category":54,"collectionId":55,"collectionName":56,"expand":57,"id":71,"views":72},"wqxt7ag2gn7xcmk","pbc_2105096300","school_blogs",{"category":58},{"blogIds":59,"collectionId":60,"collectionName":61,"created":62,"created_by":13,"id":54,"image":63,"image_alt":13,"image_path":64,"label":65,"name":66,"priority":67,"publish_at":68,"scheduled_at":13,"status":69,"updated":70,"updated_by":13},[],"sclcatblg987654321","school_category_blogs","2026-03-04 08:33:53.210Z","59ty92ns80w_15oc1implw.png","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclcatblg987654321\u002Fwqxt7ag2gn7xcmk\u002F59ty92ns80w_15oc1implw.png",{"en":66,"th":66},"Golang The Series",1,"2026-03-16 04:39:38.440Z","published","2026-04-25 02:32:15.470Z","5eetr92m80djrui",254,"w3qd4tw05xso27x",[20,25,30,35,40],"2026-02-16 03:44:10.212Z","อย่าปล่อยให้ระบบล่มในคืนสำคัญ! มาเรียนรู้วิธีการทำ Load และ Stress Testing สำหรับ WebSocket ด้วย k6 เจาะลึกการหาจุดแตกหัก (Breaking Point) และเทคนิคการจูน OS\u002FGo ให้รองรับคนนับแสน","golang-websocket-load-stress-testing-k6-guide","2026-04-25 02:47:40.809Z",{"th":77}]