Skip to content

Commit 1ec029d

Browse files
zaaackalfonsogarciacaro
authored andcommitted
Update ssr benchmark
1 parent d18b961 commit 1ec029d

File tree

4 files changed

+44
-26
lines changed

4 files changed

+44
-26
lines changed

Samples/SSRSample/benchmark/dotnet.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let initState: Model = {
1515
}
1616

1717
let coreCount = Environment.ProcessorCount
18-
let workerTimes = 5000
18+
let workerTimes = 20_000
1919
let totalTimes = workerTimes * coreCount
2020
let mutable totalms = 0L
2121

@@ -36,7 +36,7 @@ let render times () =
3636
int watch.ElapsedMilliseconds
3737

3838
let singleTest () =
39-
let times = workerTimes * 2
39+
let times = totalTimes
4040
let time = render times ()
4141
printfn "[Single thread] %dms %.3freq/s" time ((float times) / (float time) * 1000.)
4242

Samples/SSRSample/benchmark/node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const initState = {
1414

1515
const noop = () => {}
1616
const mb = bytes => (bytes / 1024 / 1024).toFixed(3)
17-
const workerTimes = 5000
17+
const workerTimes = 20000
1818
const totalTimes = workerTimes * coreCount
1919

2020
function render(len = workerTimes) {
@@ -26,7 +26,7 @@ function render(len = workerTimes) {
2626
}
2727

2828
function singleTest() {
29-
const times = workerTimes * 2
29+
const times = totalTimes
3030
const time = render(times)
3131
console.log(`[Single process] ${time}ms ${(times / time * 1000).toFixed(3)}req/s`)
3232
}

Samples/SSRSample/build.fsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ Target "Run" (fun () ->
100100
==> "Run"
101101

102102

103-
"BuildBench"
103+
"InstallClient"
104+
==> "RestoreServer"
105+
==>"BuildBench"
104106
==> "Bench"
105107

106108
RunTargetOrDefault "Build"

docs/server-side-rendering.md

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ There are lots of articles about comparing dotnet core and nodejs, I will only m
3232
* F# is a compiled language, which means it's generally considered faster then a dynamic language, like js.
3333
* Nodejs's single thread, event-driven, non-blocking I/O model works well in most web sites, but it is not good at CPU intensive tasks, including html rendering. Usually we need to run multi nodejs instances to take the advantage of multi-core systems. DotNet support non-blocking I/O (and `async/await` sugar), too. But the awesome part is that it also has pretty good support for multi-thread programming.
3434

35-
In a simple test in my local macbook, rendering on dotnet core is about ~3x faster then nodejs (with ReactDOMServer.renderToString + NODE_ENV=production). You can find more detail in the bottom of this page.
35+
In a simple test in my local macbook, rendering on dotnet core is about ~1.5x faster then nodejs (with ReactDOMServer.renderToString + NODE_ENV=production) in a single thread. You can find more detail in the bottom of this page.
3636

3737
In a word, with this approach, you can not only get a better performance then nodejs, but also don't need the complexity of running and maintaining nodejs instances on your server!
3838

@@ -268,35 +268,51 @@ cd ./Samples/SSRSample
268268

269269
```
270270

271-
Here is the benchmark result in my laptop (MacBook Pro with 2.7 GHz Intel Core i5, 16 GB 1867 MHz DD~R3), rendering on dotnet core is about ~4x faster then on nodejs in a single thread. To take the advantage of multi-core systems, we also tested with multi-thread on dotnet core and cluster mode in nodejs, the dotnet core version is still about ~3x faster then nodejs version, with less memory footprint!
271+
Here is the benchmark result in my linux laptop (Intel Core i7-3630QM, 8 core), rendering on dotnet core is about ~1.5x faster then on nodejs in a single thread. To take the advantage of multi-core systems, we also tested with multi-thread on dotnet core and cluster mode in nodejs, the dotnet core version is still faster then nodejs version, but not much. I guess it's because multi-process takes more advantages from multi cores then multi-threaded. What's more, multi-threaded dotnet has less memory footprint.
272272

273273
```sh
274274

275275
dotnet ./bin/Release/netcoreapp2.0/dotnet.dll
276276
Thread 1 started
277-
Thread 1 render 10000 times used 2414ms
278-
[Single thread] 2414ms 4142.502req/s
277+
Thread 1 render 160000 times used 25146ms
278+
[Single thread] 25146ms 6362.841req/s
279279
Thread 1 started
280-
Thread 4 started
281280
Thread 3 started
281+
Thread 4 started
282282
Thread 5 started
283-
Thread 3 render 5000 times used 3399ms
284-
Thread 5 render 5000 times used 3401ms
285-
Thread 1 render 5000 times used 3402ms
286-
Thread 4 render 5000 times used 3405ms
287-
[4 tasks] Total: 3401ms Memory footprint: 32.184MB Requests/sec: 5880.623
283+
Thread 7 started
284+
Thread 8 started
285+
Thread 9 started
286+
Thread 6 started
287+
Thread 3 render 20000 times used 10370ms
288+
Thread 9 render 20000 times used 10409ms
289+
Thread 6 render 20000 times used 10421ms
290+
Thread 4 render 20000 times used 10434ms
291+
Thread 7 render 20000 times used 10445ms
292+
Thread 1 render 20000 times used 10458ms
293+
Thread 5 render 20000 times used 10483ms
294+
Thread 8 render 20000 times used 10497ms
295+
[8 tasks] Total: 10439ms Memory footprint: 43.266MB Requests/sec: 15327.139
288296

289297
/usr/local/bin/node ./node.js
290-
Master 78856 is running
291-
[Single process] 9511ms 1051.414req/s
292-
Worker 78863: started
293-
Worker 78861: started
294-
Worker 78860: started
295-
Worker 78862: started
296-
Worker 78863: render 5000 times used 10390ms
297-
Worker 78861: render 5000 times used 10459ms
298-
Worker 78862: render 5000 times used 10528ms
299-
Worker 78860: render 5000 times used 10567ms
300-
[4 workers] Total: 10486ms Memory footprint: 104.033MB Requests/sec: 1907.305
298+
Master 3266 is running
299+
[Single process] 33702ms 4747.493req/s
300+
Worker 3275: started
301+
Worker 3281: started
302+
Worker 3303: started
303+
Worker 3289: started
304+
Worker 3304: started
305+
Worker 3296: started
306+
Worker 3320: started
307+
Worker 3317: started
308+
Worker 3281: render 20000 times used 10247ms
309+
Worker 3289: render 20000 times used 10709ms
310+
Worker 3275: render 20000 times used 11048ms
311+
Worker 3303: render 20000 times used 11119ms
312+
Worker 3296: render 20000 times used 11188ms
313+
Worker 3320: render 20000 times used 11359ms
314+
Worker 3304: render 20000 times used 11370ms
315+
Worker 3317: render 20000 times used 11574ms
316+
[8 workers] Total: 11076.75ms Memory footprint: 200.066MB Requests/sec: 14444.670
301317

302318
```

0 commit comments

Comments
 (0)