Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

go-langserver using an insane amount of cpu #1994

Closed
primalmotion opened this issue Oct 12, 2018 · 33 comments
Closed

go-langserver using an insane amount of cpu #1994

primalmotion opened this issue Oct 12, 2018 · 33 comments

Comments

@primalmotion
Copy link
Contributor

primalmotion commented Oct 12, 2018

Since the last upgrade of vscode/vscode-go go-langserver is using an insane amount of cpu after a few minutes of use (from 400% to 700%)

my config did not change, and I run update tools command

Here's the relevant part of it

{
    "go.autocompleteUnimportedPackages": true,
    "go.coverOnSingleTest": true,
    "go.coverageDecorator": {
        "type": "highlight"
    },
    "go.coverageOptions": "showUncoveredCodeOnly",
    "go.docsTool": "gogetdoc",
    "go.enableCodeLens": {
        "references": false,
        "runtest": true,
    },
    "go.formatTool": "goreturns",
    "go.languageServerExperimentalFeatures": {
        "autoComplete": false,
        "format": false
    },
    "go.buildOnSave": "package",
    "go.lintFlags": [
        "--disable-all",
        "--exclude-use-default=false",
        "--enable=errcheck",
        "--enable=goimports",
        "--enable=ineffassign",
        "--enable=golint",
        "--enable=prealloc"
    ],
    "go.lintOnSave": "package",
    "go.lintTool": "golangci-lint",
    "go.useCodeSnippetsOnFunctionSuggest": true,
    "go.useCodeSnippetsOnFunctionSuggestWithoutType": false,
    "go.useLanguageServer": true,
    "go.vetOnSave": "off",
    "go.vetFlags": [
        "-shadow",
    ],
    "go.liveErrors": {
        "enabled": true,
        "delay": 500
    },
    "go.gotoSymbol.includeGoroot": true
}
go-langserver -version
v3-dev
@ramya-rao-a
Copy link
Contributor

To first decide if this is a issue with VS Code, the Go extension or the language server, can you try with an older version of VS Code and the Go extension and check the performance?

Older version of VS Code can be found in https://code.visualstudio.com/updates

Older version of the Go extension can be found in https://github.com/Microsoft/vscode-go/releases
Just download the vsix file and run code --install-extension Go-x.y.z.vsix

@primalmotion
Copy link
Contributor Author

first thing I did was to go back to VScode version from August (using same version of language server and vscode-go). Didn't need to push the investigation further, all is working well now for 30min. So it seems the regression is from VScode. I'll continue to work with this version for a while and report if things are going crazy again.

@primalmotion
Copy link
Contributor Author

I confirm it works perfectly with vscode 1.27.2

@gow
Copy link

gow commented Oct 17, 2018

Same issue. Just upgraded to version 1.28.1 and the language server became CPU hungry.

@ramya-rao-a
Copy link
Contributor

@primalmotion, @gow You opened and worked on the same project in both new and old versions of VS Code?

@dbaeumer Any idea why the latest VS Code would cause such an issue? The version of language client used in the Go extension is 4.3.0

@gow
Copy link

gow commented Oct 17, 2018

@ramya-rao-a I didn't explicitly go back to old version to verify. But I noticed the issue as soon as I applied the update. Everything was working just fine before I updated.
I'll try to go back to previous version to verify. Will report in a bit.

@primalmotion
Copy link
Contributor Author

@ramya-rao-a yes. I worked all day on the same set of workspace as usual.

@dbaeumer
Copy link
Member

@ramya-rao-a something might have changed in VS Code which as a result pokes the server more often. One way to find this out is to enable tracing in both setups and see if there are more requests send to the server and if so which once.

@ankur-anand
Copy link

ankur-anand commented Oct 17, 2018

@ramya-rao-a I've updated the go-tool today 0.6.91 and after that, it uses a huge chunk of CPU all the time,

average load

 ankur ▶ ~/Desktop/…/twoSum ▶ $ ▶ uptime
 20:20:31 up 30 min,  1 user,  load average: 14.81, 14.53, 11.34

process info

 ankur ▶ ~/Desktop/…/twoSum ▶ $ ▶ ps -eo pcpu,pid,user,args | sort -k1 -r -n | head -10
52.6  5406 ankur    /usr/bin/go build -o /tmp/vscode-goKgQCYU/go-code-check .
51.6  5415 ankur    /usr/bin/go vet ./...
51.4  5600 ankur    /usr/bin/go build -o /tmp/vscode-goKgQCYU/go-code-check .
51.2  5596 ankur    /usr/bin/go vet ./...
41.9  7757 ankur    go list -e -json -compiled -test=true -export=true -deps=true -tags= -- .
41.8  7644 ankur    /usr/bin/go build -o /tmp/vscode-gosPJvQE/go-code-check .
41.7  7784 ankur    /usr/bin/go vet ./...
41.5  7640 ankur    /usr/bin/go vet ./...
41.3  7791 ankur    /usr/bin/go build -o /tmp/vscode-gosPJvQE/go-code-check .
 3.7 13848 ankur    /usr/lib/chromium-browser/chromium-browser --type=renderer --field-trial-handle=16958379901938881904,8968544606741407184,131072 --service-pipe-token=7304318142105071701 --lang=en-US --enable-offline-auto-reload --enable-offline-auto-reload-visible-only --num-raster-threads=2 --enable-main-frame-before-activation --service-request-channel-token=7304318142105071701 --renderer-client-id=45 --shared-files=v8_context_snapshot_data:100,v8_natives_data:101

Next highest usage after go process is chromium process and its only consuming 3.7% of cpu, as compared to all other go process consuming around 50%

Observation:

Multiple go vet process keeps running along with the corresponding go build, even when vscode has been closed.

go version
go version go1.11 linux/amd64

CPU Consuming most time in the User Space

 ankur ▶ ~/Desktop/…/twoSum ▶ $ ▶  mpstat
Linux 4.15.0-36-generic (thinkpad-e470) 	10/17/2018 	_x86_64_	(4 CPU)

08:17:21 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
08:17:21 PM  all   78.19    0.06    3.00    0.26    0.00    0.22    0.00    0.00    0.00   18.27

@dbaeumer I closed the vscode process and waited for 15min but the CPU load never went down. And this issue started coming after tool update only.

@gow
Copy link

gow commented Oct 17, 2018

I confirmed that VS Code 1.27.2 doesn't have this issue with same Go extension 0.6.91

@ramya-rao-a
Copy link
Contributor

@ankur-anand This issue is tracking the problem of the Go language server consuming a lot of CPU where as your issue is independent of the Go language server, therefore can you please log a separate issue and we can take it from there?

@primalmotion
Copy link
Contributor Author

there is a related issue there sourcegraph/go-langserver#209

@huttarichard
Copy link

having same issue, for me os crashed sourcegraph/go-langserver#336

@ramya-rao-a
Copy link
Contributor

@huttarichard Do you also not see the problem in 1.27.2? You can get the older version from https://code.visualstudio.com/updates/v1_27

@huttarichard
Copy link

@ramya-rao-a I can confirm, so far did not happen

@pmalekn
Copy link

pmalekn commented Nov 8, 2018

I am only using vs code with Go for a couple of weeks and using langserver was always causing huge CPU spikes and memory consumption. VS code version 1.28.2, go plugin 0.7.0, go-langserver SHA 0ed1299806f7c16c0fd25d9ac31ef20e48cd4ce0.

Attaching cpu and heap profiles if that might help anyone. (while creating the heap profile langserver was using around 14 gigs of memory - at least that's what Activity Monitor said)

pprof.alloc_objects.alloc_space.inuse_objects.inuse_space.001.pb.gz
pprof.samples.cpu.001.pb.gz

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Nov 9, 2018

@pmalekn Can you also check if you see the same when using VS Code 1.27? https://code.visualstudio.com/updates/v1_27

Also give the Insiders a try

@pmalekn
Copy link

pmalekn commented Nov 9, 2018

@ramya-rao-a 1.27.2 seems better after using it for a while but I wouldn't like to bet on it. I've left go-langserver version as described in my previous post and now I don't see those memory and CPU spikes

@primalmotion
Copy link
Contributor Author

primalmotion commented Nov 12, 2018

still miserable with vscode 1.29.0

The only way to make this manageable is to run:

while true; do sleep 60; pkill go-langserver; done

@ramya-rao-a
Copy link
Contributor

@primalmotion Does this occur even in simple small code bases? If not, then can you point me to a codebase where you see this consistently? What worries me is that this is a recent issue with recent VS Code versions. So even though there is a tracking issue in the language server repo, this can be something triggered by a recent change in VS Code itself.

@primalmotion
Copy link
Contributor Author

@ramya-rao-a I mostly work on our internal projects so I don't have much to share. It happens on large codebase or small libs.

But from my experimentations yeah it seems to be VSCode as when I downgraded, even with latest go-langserver and latest go extension, everything was fine.

But I don't notice any spamming of any sort in the go-langserver output console even in trace mode

@sandipb
Copy link

sandipb commented Nov 15, 2018

@ramya-rao-a I have been closely looking at this because it has been significantly hampering my development. I looked closely, for example at the traces of the langserver.

One odd thing stood out - currently, when I am typing in the code editor, it seems that vscode sends a notif: textDocument/didChange message, and then a request #n: textDocument/documentSymbol request on every character being entered in the editor. This causes an insane amount of unnecessary chatter for a line of text being input.

Is this by the protocol design?

Can this be, in some ways debounced and so the messages only sent after a minimum x millis?

Can this be configurable? Like, if I want to only care about getting popup help after I pause typing for 500ms?

I am just guessing out there, that a possible edge case is being triggered in the lang server because two many requests are being sent for the same document, and we can reduce this a bit by asking langserver less frequently by cutting down on obvious unnecessary calls.

@dbaeumer
Copy link
Member

dbaeumer commented Nov 19, 2018

@jrieken could this (microsoft/vscode#47265) be caused by the outline view?

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Nov 20, 2018

@sandipb Thats a good observation. Disable both the outline view in the explorer viewlet and the breadcrumbs feature and see if that makes any difference.

Outline view:

  • Open the File explorer
  • Right-click on the section header "OUTLINE" to disable it

Breadcrumbs:

  • View -> Toggle Breadcrumbs to disable it

@primalmotion Can you try the same?

@sandipb
Copy link

sandipb commented Nov 21, 2018

Lol. I didn't even know that Breadcrumbs was a feature. Didn't have it on.

Just now had an editing session with the outline disabled. Still had the issue with langserver.

Is there a way to force the outline view to use the default outline cli (go-outline) regardless of whether langserver is enabled?

@ramya-rao-a
Copy link
Contributor

@sandipb

Is there a way to force the outline view to use the default outline cli (go-outline) regardless of whether langserver is enabled?

The outline view in the explorer uses the same code that powers the Go to Symbol in file command. At the moment, there we dont allow the pick and choose of features from the language server

Just now had an editing session with the outline disabled. Still had the issue with langserver.

Keep the outline view and breadcrumbs disabled, kill the current language server process and try again just to be sure.

When you observed the trace logs in #1994 (comment), did you by any chance get to compare it with the logs you get when using the older VS Code

@jrieken
Copy link
Member

jrieken commented Nov 21, 2018

@jrieken could this (microsoft/vscode#47265) be caused by the outline view?

We have shipped outline view in summer and we didn't change how it schedules its updates. I'd be surprised if this is coming only now.

@primalmotion
Copy link
Contributor Author

primalmotion commented Nov 21, 2018

I tried to disable breadcrumb and outline view, doesn't improve anything for me

@ghost
Copy link

ghost commented Dec 14, 2018

I have the same issue, did someone fix this problem?

@ColtonProvias
Copy link

It looks like everybody is just waiting for the official Go langserver to be released, which could be a while. Even over on Sourcegraph's repository, they are advocating just waiting for the official server to ship.

Still, it's not helpful in the interim for us suffering from this bug.

@tj
Copy link

tj commented Jan 10, 2019

not sure if this is related, autocomplete works fine for a while, but after maybe ~30 minutes I run into cases where it spawns a ton of these processes

screen shot 2019-01-01 at 4 49 34 pm

@primalmotion
Copy link
Contributor Author

we're getting closer sourcegraph/go-langserver#209 (comment)

@ramya-rao-a
Copy link
Contributor

Closing this issue as we have now moved to suggesting gopls as the language server of choice than go-langserver

For more on language server integration with this extension, please see Go language server

To go a feature request for gopls, use the Go issue tracker

@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests