<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:series="https://publishpress.com/"
	>

<channel>
	<title>Stress Test Archives - Tomoshare</title>
	<atom:link href="https://blog.tomosia.com.vn/danh-muc/test/stress-test/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.tomosia.com.vn/danh-muc/test/stress-test/</link>
	<description>Kênh chia sẻ kiến thức Tomosia Việt Nam</description>
	<lastBuildDate>Fri, 24 Oct 2025 02:09:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://blog.tomosia.com.vn/wp-content/uploads/2023/09/cropped-icon-32x32.png</url>
	<title>Stress Test Archives - Tomoshare</title>
	<link>https://blog.tomosia.com.vn/danh-muc/test/stress-test/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Stress Test with AWS Worker</title>
		<link>https://blog.tomosia.com.vn/stress-test-with-aws-worker/</link>
					<comments>https://blog.tomosia.com.vn/stress-test-with-aws-worker/#comments</comments>
		
		<dc:creator><![CDATA[phi lai]]></dc:creator>
		<pubDate>Thu, 23 Oct 2025 10:37:36 +0000</pubDate>
				<category><![CDATA[Stress Test]]></category>
		<guid isPermaLink="false">https://blog.tomosia.com.vn/?p=3457</guid>

					<description><![CDATA[<p>1. Mục tiêu của stress test chịu tải trong hệ thống (AWS EC2 Worker và SQS) Khi hệ&#8230;</p>
<p>The post <a href="https://blog.tomosia.com.vn/stress-test-with-aws-worker/">Stress Test with AWS Worker</a> appeared first on <a href="https://blog.tomosia.com.vn">Tomoshare</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h3 id="1-muc-tieu-cua-stress-test-chiu-tai-trong-he-thong-aws-ec2-worker-va-sqs" class="wp-block-heading">1. Mục tiêu của stress test chịu tải trong hệ thống (AWS EC2 Worker và SQS)</h3>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="576" src="https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-2-1024x576.png" alt="Kiến trúc AWS EC2 Worker SQS" class="wp-image-3458" srcset="https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-2-1024x576.png 1024w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-2-300x169.png 300w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-2-768x432.png 768w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-2-380x214.png 380w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-2-800x450.png 800w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-2-1160x653.png 1160w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-2.png 1344w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">Khi hệ thống xử lý theo mô hình bất đồng bộ (asynchronous) — trong đó API nhận dữ liệu, đẩy vào hàng đợi (queue), và worker chạy nền (trên EC2) xử lý dần — việc đánh giá khả năng chịu tải không chỉ là đo tốc độ phản hồi API mà là <strong>đánh giá toàn bộ chuỗi xử lý message</strong>.</p>



<p class="wp-block-paragraph">Stress test giúp xác định hệ thống có thể hấp thụ và xử lý bao nhiêu message mỗi giây, khi worker EC2 thực thi song song trên nhiều thread. Đây là bài test quan trọng để tối ưu số lượng instance, cấu hình thread pool và giới hạn throughput của hàng đợi SQS.</p>



<ul class="wp-block-list">
<li>Đo thời gian trung bình để xử lý một lượng lớn message.</li>



<li>Xác định giới hạn throughput trước khi queue backlog.</li>



<li>Phát hiện điểm nghẽn (bottleneck) ở tầng API, SQS hoặc Worker.</li>



<li>Đánh giá mức ổn định và khả năng phục hồi khi tải giảm.</li>
</ul>



<h3 id="2-kien-truc-ha-tang-dung-de-stress-test" class="wp-block-heading">2. Kiến trúc hạ tầng dùng để stress test</h3>



<p class="wp-block-paragraph">Dưới đây là kiến trúc tham chiếu của hệ thống AWS EC2 Worker &amp; SQS trong bài test:</p>



<figure class="wp-block-table is-style-stripes"><table class="has-fixed-layout"><thead><tr><th>Thành phần</th><th>Vai trò</th><th>Ghi chú khi test</th></tr></thead><tbody><tr><td><strong>API Gateway</strong></td><td>Nhận request từ JMeter và đẩy payload vào SQS.</td><td>Bật log để theo dõi tốc độ gửi và lỗi HTTP.</td></tr><tr><td><strong>Amazon SQS</strong></td><td>Hàng đợi lưu message cần xử lý.</td><td>Dùng <em>Standard Queue</em> để đạt throughput cao nhất.</td></tr><tr><td><strong>EC2 Worker (Java)</strong></td><td>Ứng dụng Java chạy trên EC2, đọc message từ SQS và xử lý nghiệp vụ.</td><td>Chạy nhiều thread song song; điều chỉnh thread pool để tối ưu hiệu năng.</td></tr><tr><td><strong>Amazon RDS</strong></td><td>Lưu kết quả xử lý hoặc log hệ thống.</td><td>Tối ưu connection pool (HikariCP hoặc datasource) để tránh quá tải.</td></tr><tr><td><strong>CloudWatch</strong></td><td>Thu thập metric từ SQS và EC2.</td><td>Theo dõi CPU, queue depth, backlog, throughput.</td></tr></tbody></table></figure>



<h3 id="3-chuan-bi-du-lieu-test" class="wp-block-heading">3. Chuẩn bị dữ liệu test</h3>



<p class="wp-block-paragraph">Dữ liệu test cần mô phỏng hành vi thật của hệ thống, bao gồm payload gửi vào API và cấu hình tốc độ bắn tải. Thông thường, các test case được lưu trong file Excel — mỗi sheet là một loại test (load, spike, stability&#8230;).</p>



<figure class="wp-block-table is-style-stripes"><table class="has-fixed-layout"><thead><tr><th>Tên test</th><th>Số request</th><th>Ramp-up time (giây)</th><th>Tốc độ gửi (req/s)</th><th>Mục tiêu</th></tr></thead><tbody><tr><td><code>Load_500_60</code></td><td>500</td><td>60</td><td>~8</td><td>Đo năng lực xử lý trung bình</td></tr><tr><td><code>Spike_2000_60</code></td><td>2000</td><td>60</td><td>~33</td><td>Kiểm tra phản ứng khi tải tăng nhanh</td></tr><tr><td><code>Stable_10000_300</code></td><td>10000</td><td>300</td><td>~33</td><td>Đánh giá độ ổn định dài hạn</td></tr></tbody></table></figure>



<h4 id="vi-du-ket-qua-thuc-te-case-1-500-threads-60-giay" class="wp-block-heading">Ví dụ: Kết quả thực tế Case 1 (500 threads / 60 giây)</h4>



<p class="wp-block-paragraph">Dưới đây là kết quả kiểm thử được ghi nhận (theo file Excel và log giám sát thực tế):</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="152" src="https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-3-1024x152.png" alt="" class="wp-image-3459" srcset="https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-3-1024x152.png 1024w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-3-300x44.png 300w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-3-768x114.png 768w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-3-1536x227.png 1536w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-3-380x56.png 380w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-3-800x118.png 800w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-3-1160x172.png 1160w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-3.png 1729w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">Trong bài test này (Case 1), hệ thống được giả lập với <strong>500 người dùng đồng thời</strong> trong vòng <strong>60 giây</strong>. </p>



<p class="wp-block-paragraph">Kết quả cho thấy throughput trung bình đạt khoảng <strong>8.3 requests/giây</strong> với <strong>100% thành công</strong>, thời gian phản hồi trung bình là <strong>227ms</strong> và cực đại là <strong>307ms</strong>.</p>



<p class="wp-block-paragraph"> Điều này cho thấy hệ thống có khả năng xử lý ổn định ở <strong>mức tải trung bình.</strong></p>



<p class="wp-block-paragraph">Jmeter</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="123" src="https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-4-1024x123.png" alt="" class="wp-image-3460" srcset="https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-4-1024x123.png 1024w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-4-300x36.png 300w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-4-768x92.png 768w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-4-380x46.png 380w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-4-800x96.png 800w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-4-1160x139.png 1160w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-4.png 1449w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">EC2</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1022" height="364" src="https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-5.png" alt="" class="wp-image-3461" srcset="https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-5.png 1022w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-5-300x107.png 300w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-5-768x274.png 768w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-5-380x135.png 380w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-5-800x285.png 800w" sizes="auto, (max-width: 1022px) 100vw, 1022px" /></figure>



<p class="wp-block-paragraph">Worker</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="1000" height="355" src="https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-6.png" alt="" class="wp-image-3462" srcset="https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-6.png 1000w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-6-300x107.png 300w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-6-768x273.png 768w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-6-380x135.png 380w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-6-800x284.png 800w" sizes="auto, (max-width: 1000px) 100vw, 1000px" /></figure>



<p class="wp-block-paragraph">RDS</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="538" height="362" src="https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-7.png" alt="" class="wp-image-3463" srcset="https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-7.png 538w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-7-300x202.png 300w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-7-380x256.png 380w" sizes="auto, (max-width: 538px) 100vw, 538px" /></figure>



<p class="wp-block-paragraph">SQS</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="312" src="https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-8-1024x312.png" alt="" class="wp-image-3464" srcset="https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-8-1024x312.png 1024w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-8-300x91.png 300w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-8-768x234.png 768w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-8-380x116.png 380w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-8-800x244.png 800w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-8-1160x353.png 1160w, https://blog.tomosia.com.vn/wp-content/uploads/2025/10/image-8.png 1448w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">Mẫu Jmeter setting</p>



<pre class="wp-block-code"><code>CSV Data Set Config: Filename: data_test.csv 
Variable Names: message_id,payload 
Recycle on EOF: True 
HTTP Body: { 
  "messageId": "${message_id}",
  "payload": "${payload}",
  "timestamp": "${__time(yyyy-MM-dd'T'HH:mm:ss)}"
 }</code></pre>



<h3 id="4-cau-hinh-jmeter-de-gui-du-lieu-len-aws" class="wp-block-heading">4. Cấu hình JMeter để gửi dữ liệu lên AWS</h3>



<p class="wp-block-paragraph">Công cụ được sử dụng là <strong>Apache JMeter</strong> — chuyên dùng để tạo tải HTTP và kiểm tra hiệu năng API. Mỗi request được gửi tới API Gateway, sau đó dữ liệu được đẩy vào hàng đợi SQS để worker EC2 xử lý.</p>



<pre class="wp-block-code"><code>Thread Group:
  Number of Threads (users): 500
  Ramp-up Period: 60
  Loop Count: 1

HTTP Request Sampler:
  Method: POST
  URL: https://{api-id}.execute-api.{region}.amazonaws.com/prod/push
  Body Data:
  {
    "messageId": "${__UUID()}",
    "payload": "${__RandomString(32,ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890)}",
    "timestamp": "${__time(yyyy-MM-dd'T'HH:mm:ss)}"
  }

HTTP Header Manager:
  Content-Type: application/json
  x-api-key: ${API_KEY}</code></pre>



<p class="wp-block-paragraph">Chạy test bằng chế độ non-GUI để tiết kiệm tài nguyên:</p>



<pre class="wp-block-code"><code>jmeter -n -t HTTPRequest_500_60_001.jmx -l results.csv -JAPI_KEY=xxxx</code></pre>



<p class="wp-block-paragraph">Nếu cần mô phỏng tăng tải dần, bạn có thể dùng plugin <strong>Stepping Thread Group</strong> để tăng số luồng từng giai đoạn, giúp kết quả thực tế hơn.</p>



<h3 id="5-giam-sat-ec2-worker-va-hang-doi-sqs" class="wp-block-heading">5. Giám sát EC2 Worker và hàng đợi SQS</h3>



<p class="wp-block-paragraph">Trong quá trình test, CloudWatch là công cụ chính để giám sát hệ thống. Các metric cần chú ý:</p>



<figure class="wp-block-table is-style-stripes"><table class="has-fixed-layout"><thead><tr><th>Metric</th><th>Nguồn</th><th>Ý nghĩa</th></tr></thead><tbody><tr><td><code>ApproximateNumberOfMessagesVisible</code></td><td>SQS</td><td>Số message đang chờ xử lý. Nếu tăng liên tục → worker xử lý không kịp.</td></tr><tr><td><code>ApproximateAgeOfOldestMessage</code></td><td>SQS</td><td>Tuổi của message lâu nhất trong queue. Nếu tăng nhanh → có backlog.</td></tr><tr><td><code>CPUUtilization</code></td><td>EC2</td><td>Theo dõi mức sử dụng CPU của worker Java.</td></tr><tr><td><code>NetworkIn/Out</code></td><td>EC2</td><td>Lưu lượng xử lý qua API hoặc đọc/ghi dữ liệu.</td></tr><tr><td><code>DBConnections</code></td><td>RDS</td><td>Số kết nối tới cơ sở dữ liệu. Nếu tăng đột biến → nghẽn kết nối.</td></tr></tbody></table></figure>



<h3 id="6-phan-tich-ket-qua-va-danh-gia-he-thong" class="wp-block-heading">6. Phân tích kết quả và đánh giá hệ thống</h3>



<p class="wp-block-paragraph">Sau khi test, cần đối chiếu kết quả từ JMeter (thời gian phản hồi, throughput) với metric từ CloudWatch (queue depth, CPU, backlog). Một hệ thống tốt là khi:</p>



<ul class="wp-block-list">
<li>Queue depth không tăng mãi, mà dao động quanh ngưỡng ổn định.</li>



<li>CPU trên EC2 được sử dụng hiệu quả (~60–80%), không nghẽn 100% liên tục.</li>



<li>Throughput duy trì ổn định trong suốt thời gian test.</li>



<li>Số message trong DLQ = 0 hoặc rất thấp.</li>
</ul>



<h3 id="7-ket-luan" class="wp-block-heading">7. Kết luận</h3>



<p class="wp-block-paragraph">Stress test trên AWS EC2 Worker và SQS giúp bạn hiểu được giới hạn chịu tải của hệ thống cũng như khả năng tự phục hồi sau khi backlog.  
Khi theo dõi đúng metric và xác định rõ “ngưỡng nghẽn” (bottleneck), bạn có thể điều chỉnh thread pool, số lượng EC2 instance hoặc kích thước hàng đợi để đạt hiệu suất tối ưu.</p>



<h4 id="tai-lieu-tham-khao" class="wp-block-heading">Tài liệu tham khảo</h4>



<ul class="wp-block-list">
<li><a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-monitoring.html" target="_blank">Amazon SQS Monitoring Guide</a></li>



<li><a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/monitoring-system-instance.html" target="_blank">Amazon EC2 Monitoring</a></li>



<li><a href="https://jmeter.apache.org/usermanual/" target="_blank">Apache JMeter User Manual</a></li>



<li><a href="https://aws.amazon.com/blogs/compute/" target="_blank">AWS Compute Blog</a></li>
</ul>
<p>The post <a href="https://blog.tomosia.com.vn/stress-test-with-aws-worker/">Stress Test with AWS Worker</a> appeared first on <a href="https://blog.tomosia.com.vn">Tomoshare</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.tomosia.com.vn/stress-test-with-aws-worker/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
	</channel>
</rss>
