"go test -cpuprofile" does not generate a full trace - go

Issue
I have a go package, with a test suite.
When I run the test suite for this package, the total runtime is ~ 7 seconds :
$ go test ./mydbpackage/ -count 1
ok mymodule/mydbpackage 7.253s
However, when I add a -cpuprofile=cpu.out option, the sampling does not cover the whole run :
$ go test ./mydbpackage/ -count 1 -cpuprofile=cpu.out
ok mymodule/mydbpackage 7.029s
$ go tool pprof -text -cum cpu.out
File: mydbpackage.test
Type: cpu
Time: Aug 6, 2020 at 9:42am (CEST)
Duration: 5.22s, Total samples = 780ms (14.95%) # <--- depending on the runs, I get 400ms to 1s
Showing nodes accounting for 780ms, 100% of 780ms total
flat flat% sum% cum cum%
0 0% 0% 440ms 56.41% testing.tRunner
10ms 1.28% 1.28% 220ms 28.21% database/sql.withLock
10ms 1.28% 2.56% 180ms 23.08% runtime.findrunnable
0 0% 2.56% 180ms 23.08% runtime.mcall
...
Looking at the collected samples :
# sample from another run :
$ go tool pprof -traces cpu.out | grep "ms " # get the first line of each sample
10ms runtime.nanotime
10ms fmt.(*readRune).ReadRune
30ms syscall.Syscall
10ms runtime.scanobject
10ms runtime.gentraceback
...
# 98 samples collected, for a total sum of 1.12s
The issue I see is : for some reason, the sampling profiler stops collecting samples, or is blocked/slowed down at some point.
Context
go version is 1.14.6, platform is linux/amd64
$ go version
go version go1.14.6 linux/amd64
This package contains code that interact with a database, and the tests are run against a live postgresql server.
One thing I tried : t.Skip() internally calls runtime.Goexit(), so I replaced calls to t.Skip and variants with a simple return ; but it didn't change the outcome.
Question
Why aren't more samples collected ? I there some known pattern that blocks/slows down the sampler, or terminates the sampler earlier than it should ?

#Volker guided me to the answer in his comments :
-cpuprofile creates a profile in which only goroutines actively using the CPU are sampled.
In my use case : my go code spends a lot of time waiting for the answers of the postgresql server.
Generating a trace using go test -trace=trace.out, and then extracting a network blocking profile using go tool trace -pprof=net trace.out > network.out yielded much more relevant information.
For reference, on top of opening the complete trace using go tool trace trace.out, here are the values you can pass to -pprof= :
from go tool trace docs :
net: network blocking profile
sync: synchronization blocking profile
syscall: syscall blocking profile
sched: scheduler latency profile

Related

Sometimes when I run `npx hardhat compile` I get this error: FATAL ERROR: NewNativeModule Allocation failed - process out of memor

Sometimes when I run this command npx hardhat compile on my windows cli I get the error below:
Compiling 72 files with 0.7.0
contracts/libraries/ERC20.sol: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code.
Please see https://spdx.org for more information.
contracts/libraries/ERC1155/EnumerableSet.sol:158:5: Warning: Variable is shadowed in inline assembly by an instruction of the same name
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
^ (Relevant source part starts here and spans across multiple lines).
contracts/libraries/ERC1155/EnumerableSet.sol:224:5: Warning: Variable is shadowed in inline assembly by an instruction of the same name
function add(AddressSet storage set, address value) internal returns (bool) {
^ (Relevant source part starts here and spans across multiple lines).
Compiling 1 file with 0.8.0
<--- Last few GCs --->
[8432:042B0460] 263058 ms: Mark-sweep (reduce) 349.8 (356.3) -> 248.2 (262.4) MB, 434.4 / 0.2 ms (+ 70.9 ms in 3 steps since start of marking, biggest step 69.6 ms, walltime since start of marking 800 ms) (average mu = 0.989, current mu = 0.990) memory[8432:042B0460] 263627
ms: Mark-sweep (reduce) 248.2 (259.4) -> 248.2 (252.1) MB, 555.5 / 0.0 ms (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 556 ms) (average mu = 0.969, current
mu = 0.023) memory p
<--- JS stacktrace --->
FATAL ERROR: NewNativeModule Allocation failed - process out of memory`
After some time the error just kind of goes away.
It goes away probably after I've restarted my system or created a new Hardhat project and imported the code there.
But this is happening too often, what could be the cause?
I've done quite some research and some answers suggested it might be a problem with Node and the application's memory allocation, but I don't know how I would apply the solutions to a Hardhat project.
Here is a link to one possible solution: https://medium.com/#vuongtran/how-to-solve-process-out-of-memory-in-node-js-5f0de8f8464c
OS: WINDOWS 10
CLI: WINDOWS CMD

Measure performance of a VPS intended for hosting a website

I just bought for a month an extremely cheap VPS with 16 GB RAM and 6 cores(from Contabo)
Now my question is, how can I get some benchmark results in order to compare it with other VPSes like Hostinger provides?
I did a Geekbench benchmark on it and the results can be seen here: https://browser.geekbench.com/v4/cpu/15852309
The problem with Geekbench is that I feel it's not really web oriented as the scores are influenced by the GPU as well.
What should I use in order to compare the VPSes between them?
Would the plan be enough to host a Magento 2 website / possibly more?
For webserver performance the Network, Disk (random read) and CPU performance are the most important factors.
I like to benchmark and compare each one separately.
For Disk I/O performance, can use sysbench:
apt install sysbench
sysbench fileio --file-num=4 prepare
sysbench fileio --file-num=4 --file-test-mode=rndrw run
For CPU performance can use stress-ng:
apt install stress-ng
stress-ng -t 5 -c 2 --metrics-brief
-c 2 uses 2 logical processors. Adjust if necessary.
For network performance can use speedtest-cli:
apt install speedtest-cli
speedtest-cli
Example output:
# sysbench fileio --file-num=4 --file-test-mode=rndrw run
<skip>
Throughput:
read, MiB/s: 45.01
written, MiB/s: 30.00
# stress-ng -t 5 -c 2 --metrics-brief
stress-ng: info: [14993] dispatching hogs: 2 cpu
stress-ng: info: [14993] successful run completed in 5.00s
stress-ng: info: [14993] stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s
stress-ng: info: [14993] (secs) (secs) (secs) (real time) (usr+sys time)
stress-ng: info: [14993] cpu 3957 5.00 9.99 0.00 790.92 396.10
# speedtest-cli
Retrieving speedtest.net configuration...
Testing from <skip> ...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by Uganda Hosting Limited (Helsinki) [0.20 km]: 1.807 ms
Testing download speed................................................................................
Download: 575.68 Mbit/s
Testing upload speed................................................................................................
Upload: 499.89 Mbit/s

Jmeter master slave not all threads finishing

I have a master/slave for jmeter set up using jmeter 5.1
For time to time I am noticing the tests just hangs up while waiting for threads to shutdown.
In the jmeter.logs I am seeing:
2020-02-06 00:06:35,100 INFO o.a.j.r.Summariser: summary + 9 in 00:30:34 = 0.0/s Avg: 5647 Min: 5520 Max: 5833 Err: 0 (0.00%) Active: 1 Started: 4 Finished: 3
I tried waiting but it never finishes this 1 active thread and it causes issue for rest of the steps I have in the pipeline to read the jmeter test result file and generate HTML report.
Any suggestions how to debug this?
I saw this post:
Threads keep running even after test finishes in Jmeter
But would be nice to understand the issue, rather than just forcing the threads to stop.
Regards,
Vikas
If you want to "understand" the issue you need to understand what this thread is doing and the only way to get the information is taking a JVM thread dump, the options are in:
Starting from JMeter version 3.2 there is an option to take a thread dump directly from JMeter GUI
You can use jstack tool and provide to it the PID of the Java process where JMeter is running
On Linux you can use kill -3 command which will print the status of threads into the console window
You can also check jmeter-server.log for for any suspicious entries.

Is it possible to disable type checks when transpiling typescript via tsc to speed up transpiling?

TypeScript checks the entire codebase on transpiling, even if only one file has actually changed. For small projects, that is fine, yet since our codebase grew, it takes quite a long time.
During development, I want quick response time of my unit tests. The unit test should run as soon as possible.
Unfortunately, I have to wait on each run about 10-15 seconds for the unit test to even start as the the tsc takes a long time to transpile, and of that time 60%-80% is spent on checking.
These example runs are just from removing and adding a newline in one file:
yarn tsc v0.27.5
$ "/home/philipp/fancyProject/node_modules/.bin/tsc" "--watch" "--diagnostics"
Files: 511
Lines: 260611
Nodes: 898141
Identifiers: 323004
Symbols: 863060
Types: 302553
Memory used: 704680K
I/O read: 0.17s
I/O write: 0.09s
Parse time: 2.61s
Bind time: 0.95s
Check time: 7.65s
Emit time: 1.45s
Total time: 12.65s
00:35:34 - Compilation complete. Watching for file changes.
00:41:58 - File change detected. Starting incremental compilation...
Files: 511
Lines: 260612
Nodes: 898141
Identifiers: 323004
Symbols: 863060
Types: 302553
Memory used: 1085950K
I/O read: 0.00s
I/O write: 0.04s
Parse time: 0.68s
Bind time: 0.00s
Check time: 12.65s
Emit time: 1.36s
Total time: 14.69s
00:42:13 - Compilation complete. Watching for file changes.
00:42:17 - File change detected. Starting incremental compilation...
Files: 511
Lines: 260611
Nodes: 898141
Identifiers: 323004
Symbols: 863060
Types: 302553
Memory used: 1106446K
I/O read: 0.00s
I/O write: 0.12s
Parse time: 0.32s
Bind time: 0.01s
Check time: 9.28s
Emit time: 0.89s
Total time: 10.50s
00:42:27 - Compilation complete. Watching for file changes.
I wonder if there is a way to tell typescript:
Just treat everything as OK and just dump the JavaScript as quickly as possible to the disk.
I want to ensure first that my unit test pass in order to have a quick feedback loop.
And since my IDE takes care of the type checks already within the file I am currently working on, I rarely have mistake in the check of the transpiling anyway. And if there was a big issue, my unit tests should catch them.
When building the project, I would just use the classic tsc with the checks. As I have said, this is only for development and having a quick feedback loop.
Start using WebPack
Add awesome-typescript-loader
Set transpileOnly in setting to true
Also you can change other paramers, which can boost speed: ignoreDiagnostics, forceIsolatedModules, etc.

Why can't I see my own application functions in golang's pprof

I'm trying to debug the performance characterics of my own program so I'm following the tutorial on the golang blog. But I have 1 small issues I can't investigate the my own functions or call in the resulting profiling output. I'm using this command to build my binary:
go build -ldflags "-s -extldflags -static" -a -installsuffix cgo -o bin/brains
And when I use go tool pprof to examine the result I can only
(pprof) top10 -cum
2.38mins of 5.25mins total (45.32%)
Dropped 125 nodes (cum <= 0.03mins)
Showing top 10 nodes out of 82 (cum >= 0.81mins)
flat flat% sum% cum cum%
0.33mins 6.24% 6.24% 4.82mins 91.69% encoding/xml.(*printer).marshalStruct
0.77mins 14.62% 20.86% 4.07mins 77.51% [brains]
0.04mins 0.79% 21.64% 1.92mins 36.50% encoding/xml.(*printer).writeEnd
0.12mins 2.24% 23.88% 1.47mins 28.06% encoding/xml.(*Decoder).unmarshal
0.31mins 5.83% 29.71% 1.27mins 24.14% github.com/aws/aws-sdk-go/vendor/github.com/jmespath/go-jmespath.(*Parser).nud
0.02mins 0.41% 30.12% 1.07mins 20.43% golang.org/x/net/html.parseForeignContent
0.52mins 9.89% 40.00% 0.98mins 18.64% golang.org/x/net/html.render1
0.15mins 2.76% 42.77% 0.95mins 18.01% github.com/aws/aws-sdk-go/vendor/github.com/jmespath/go-jmespath.(*Parser).parseMultiSelectHash
0.10mins 2.00% 44.77% 0.83mins 15.86% golang.org/x/net/html.initialIM
0.03mins 0.55% 45.32% 0.81mins 15.42% golang.org/x/net/html.beforeHeadIM
As you can see a large amount of time is spend in the [brains] package, but I can't see any details of which functions like I do see for other packages!
I probably doing something very stupid wrong of course so if somebody notices my mistake I would be very thankful if you point it out to me :D
ps: I'm doing the profiling on a linux environment and the analysis on my Macbook, but I think it shouldn't matter since the binary is statically build the same for both environments
Thanks,
Niels

Resources