Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(@angular/ssr): optimized request handling performance #29909

Merged
merged 1 commit into from
Mar 21, 2025

Conversation

alan-agius4
Copy link
Collaborator

@alan-agius4 alan-agius4 commented Mar 21, 2025

This commit refactors request handling logic, leading to significant performance improvements.

Benchmark

Metric 19.2.x Branch Main Branch After Optimization Improvement vs 19.2.x Improvement vs Main
Latency (Avg) 2473.94 ms 2655.35 ms 2385.85 ms ~3.6% ~10.1%
Latency (50%) 2445.67 ms 2615 ms 2416.33 ms ~1.2% ~7.6%
Latency (97.5%) 2640.5 ms 3309 ms 2561.5 ms ~3.0% ~22.6%
Req/Sec (Avg) 398.32 364.54 400.12 ~0.4% ~9.8%
Bytes/Sec (Avg) 8.41 MB 7.7 MB 8.45 MB ~0.5% ~9.7%
Total Requests 13,000 12,000 13,000 0% ~8.3%

Test Details:

  • Command: npx autocannon -c 100 -d 30 -p 10 http://localhost:<port>
  • Parameters:
    • -c 100: 100 concurrent connections
    • -d 30: 30 seconds duration
    • -p 10: 10 pipelining factor
  • Iterations: 3 tests were run on each of the Main Branch and the 19.2.x Branch, and 3 tests were run after optimization. Average of each set of tests was used for the comparison.
  • Samples: 30 samples were collected per test run for Req/Bytes counts.

The optimized request handling logic (After Optimization) shows significant improvements across all key performance metrics compared to the original logic on the Main Branch. The regression observed in the Main Branch is attributed to the newly added header flushing logic.

When compared to the 19.2.x branch, the optimized code delivers similar performance. Latency is slightly reduced, while request throughput (Req/Sec) and data transfer rate (Bytes/Sec) have seen a slight increase. The total number of requests handled remains consistent with the 19.2.x branch.

@alan-agius4 alan-agius4 added the target: major This PR is targeted for the next major release label Mar 21, 2025
@angular-robot angular-robot bot added area: performance Issues related to performance area: @angular/ssr labels Mar 21, 2025
@alan-agius4 alan-agius4 requested a review from jkrems March 21, 2025 08:54
@alan-agius4 alan-agius4 added the action: review The PR is still awaiting reviews from at least one requested reviewer label Mar 21, 2025
@alan-agius4 alan-agius4 force-pushed the ssr-request-handling branch 2 times, most recently from 28f111a to b369eea Compare March 21, 2025 09:07
This commit refactors request handling logic, leading to significant performance improvements.

**Benchmark**

| Metric             | 19.2.x Branch         | Main Branch          | After Optimization  | Improvement vs 19.2.x | Improvement vs Main   |
|--------------------|-----------------------|----------------------|---------------------|-----------------------|-----------------------|
| Latency (Avg)      | 2473.94 ms            | 2655.35 ms           | 2385.85 ms          | ~3.6%                 | ~10.1%                |
| Latency (50%)      | 2445.67 ms            | 2615 ms              | 2416.33 ms          | ~1.2%                 | ~7.6%                 |
| Latency (97.5%)    | 2640.5 ms             | 3309 ms              | 2561.5 ms           | ~3.0%                 | ~22.6%                |
| Req/Sec (Avg)      | 398.32                | 364.54               | 400.12              | ~0.4%                 | ~9.8%                 |
| Bytes/Sec (Avg)    | 8.41 MB               | 7.7 MB               | 8.45 MB             | ~0.5%                 | ~9.7%                 |
| Total Requests     | 13,000                | 12,000               | 13,000              | 0%                    | ~8.3%                 |

**Test Details:**

* **Command:** `npx autocannon -c 100 -d 30 -p 10 http://localhost:<port>`
* **Parameters:**
    * `-c 100`: 100 concurrent connections
    * `-d 30`: 30 seconds duration
    * `-p 10`: 10 pipelining factor
* **Iterations:** 3 tests were run on each of the Main Branch and the 19.2.x Branch, and 3 tests were run after optimization. Average of each set of tests was used for the comparison.
* **Samples:** 30 samples were collected per test run for Req/Bytes counts.

The optimized request handling logic (After Optimization) shows significant improvements across all key performance metrics compared to the original logic on the Main Branch. The regression observed in the Main Branch is attributed to the newly added header flushing logic.

When compared to the 19.2.x branch, the optimized code delivers similar performance. Latency is slightly reduced, while request throughput (Req/Sec) and data transfer rate (Bytes/Sec) have seen a slight increase. The total number of requests handled remains consistent with the 19.2.x branch.
@alan-agius4 alan-agius4 force-pushed the ssr-request-handling branch from b369eea to ce0a56b Compare March 21, 2025 09:11
Copy link
Contributor

@jkrems jkrems left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat! 🎉

@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 21, 2025
@alan-agius4 alan-agius4 merged commit 6bd7b9b into angular:main Mar 21, 2025
30 of 31 checks passed
@alan-agius4 alan-agius4 deleted the ssr-request-handling branch March 21, 2025 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: @angular/ssr area: performance Issues related to performance target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants