# Terraform-ls - dealing with language server as a daemon

**URL:** <https://discuss.hashicorp.com/t/terraform-ls-dealing-with-language-server-as-a-daemon/46707>\
**Category:** Terraform Editor Integrations\
**Created:** [November 9, 2022, 8:14pm UTC](https://discuss.hashicorp.com/t/terraform-ls-dealing-with-language-server-as-a-daemon/46707 "2022-11-09T20:14:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcus](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/marcus/32/31916_2.png) [@marcus](https://discuss.hashicorp.com/u/marcus)\
**Post date:** [November 9, 2022, 8:14pm UTC](https://discuss.hashicorp.com/t/terraform-ls-dealing-with-language-server-as-a-daemon/46707/1 "2022-11-09T20:14:31Z")

</div>

After the `port` feature has been brought to `terraform-ls`, I’ve been trying to use it like a daemon, with respect to maximizing `req-concurrency` - this way I can use in multiple windows.  
However, with respect to the Visual Studio Code extension - it does not seem to have a proper configuration to lead with communicating to the language server through the TCP port and only through it.

Is there a way this could be viable?

Regards

---

<div class="post-metadata">

**Author:** ![dbanck](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/dbanck/32/23412_2.png) [@dbanck](https://discuss.hashicorp.com/u/dbanck)\
**Post date:** [November 10, 2022, 4:22pm UTC](https://discuss.hashicorp.com/t/terraform-ls-dealing-with-language-server-as-a-daemon/46707/2 "2022-11-10T16:22:39Z")

</div>

Hi @marcus,

There is an experimental setting in the extension for this:

```json
{
  "terraform.languageServer.tcp.port": 13373,
}

```

We have yet to document it because we have yet to consider this functionality production-ready and are primarily using it for debugging purposes.

You can give it a try and see if it works for you, but you’ve been warned 😉

Do you mind sharing what you’ve planned concerning maximizing req-concurrency? Instead of using multiple windows, VS Code offers [workspace support](https://code.visualstudio.com/docs/editor/workspaces), which allows you to open numerous folders while sharing a single language server instance. That would be our preferred and more stable solution than specifying a TCP port.

---

<div class="post-metadata">

**Author:** ![marcus](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/marcus/32/31916_2.png) [@marcus](https://discuss.hashicorp.com/u/marcus)\
**Post date:** [November 10, 2022, 4:45pm UTC](https://discuss.hashicorp.com/t/terraform-ls-dealing-with-language-server-as-a-daemon/46707/3 "2022-11-10T16:45:45Z")

</div>

Thanks a lot for the reply.  
I’ve found that configuration parameter while digging the source code yesterday.

The idea is to share the language server between our VS Codes that run in Windows.  
As we all know, the Go binaries generated for terraform-ls and terraform are extremely slow in comparison to ELF.

So, we’re somewhat of playing with VSCode + tunneling and some nifty tricks (to share the same language server between various people).

You have no idea of how fast it is compared to running the language server and even terraform itself in plain Windows binary.

The req-concurrency is set at 30 now.

---

<div class="post-metadata">

**Author:** ![radeksimko](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/radeksimko/32/47475_2.png) [@radeksimko](https://discuss.hashicorp.com/u/radeksimko)\
**Post date:** [November 14, 2022, 10:29am UTC](https://discuss.hashicorp.com/t/terraform-ls-dealing-with-language-server-as-a-daemon/46707/4 "2022-11-14T10:29:07Z")

</div>

> [@marcus](#):
>
> As we all know, the Go binaries generated for terraform-ls and terraform are extremely slow in comparison to ELF.

Can you expand on the “extremely slow” here? i.e. in what context is it slow? Also what do you mean by “ELF”?

> [@marcus](#):
>
> (to share the same language server between various people).

I have never seen LSP used in the context where the server is used by multiple _users_. Although it’s probably technically possible, there are likely some privacy/security aspects which the LSP as a protocol generally doesn’t account for - and hence neither does our server. We don’t do any kind of _intentional_ data separation (except what is necessary in terms of session separation), so you implicitly have to fully trust anyone who you share the server with.

In principle though we do support the concept of “sessions” which should allow multiple _clients_ to talk to the same server. We have never considered that these sessions would be owned by different users however as that’s not a use case LSP documents either AFAIK.

> [@marcus](#):
>
> The req-concurrency is set at 30 now.

There are a few reasons we keep the [concurrency](https://github.com/hashicorp/terraform-ls/blob/b1c2a7f89b05b02aad5e9749bf31331f07a72006/internal/cmd/serve_command.go#L50-L51) conservatively low at `2`:

- higher concurrency is unlikely to be useful for a single user, who would very rarely generate enough requests at the same time which would actually benefit from higher parallelism (i.e. typically a single human won’t be editing more than one file at a time).
- LSP declares, that many requests need to be processed in the same order they arrived (e.g. `textDocument/didChange`), so that pretty much implies low concurrency anyway, at least per session.

We are generally open to making performance improvements! So if you can describe the scenario in which the language server or the client (VS Code extension) are slow and we can make it faster [for everyone], we would be happy to look into that.

We do not expect our users to need to custom-compile the language server or have to tweak the `req-concurrency` flag – certainly not for performance reasons. It is there **mainly** for debugging purposes.

---

<div class="post-metadata">

**Author:** ![marcus](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/marcus/32/31916_2.png) [@marcus](https://discuss.hashicorp.com/u/marcus)\
**Post date:** [November 14, 2022, 1:58pm UTC](https://discuss.hashicorp.com/t/terraform-ls-dealing-with-language-server-as-a-daemon/46707/5 "2022-11-14T13:58:27Z")

</div>

Let’s just establish something here, the focus is not to discuss, point right or wrong, and I’m here only to learn from you guys.

The daemon apeal was just a ‘kids idea’ we had to play with it - not something that we will run and spread to be used throughout production.

Related to terraform being slow in comparion between Windows and Linux, just bring up a full VSCode with hashicorp extension and terraform+terraform-ls binaries running in Windows.

Do some terraform validate, fmt, (format-on-save might help), you will see what I’m talking about.

My experience with that was so fiercely painful that I felt I was forced to bring up a WSL environment to run everything in the WSL, except for the VS Code.

Not joking, that’s something that really requires attention.

---

<div class="post-metadata">

**Author:** ![radeksimko](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/radeksimko/32/47475_2.png) [@radeksimko](https://discuss.hashicorp.com/u/radeksimko)\
**Post date:** [November 15, 2022, 1:31pm UTC](https://discuss.hashicorp.com/t/terraform-ls-dealing-with-language-server-as-a-daemon/46707/6 "2022-11-15T13:31:21Z")

</div>

I am vaguely aware that on Windows, IPC and generally “external command execution” can be slower compared to other platforms. Admittedly, I don’t experience this myself, as I’m not a regular Windows user, so I apologise for any implied lack of empathy or knowledge in this area. 😅

I’d expect this to only impact the formatting (when we run `terraform fmt -`) or the “validate” command execution (when we run `terraform validate`). I would _not_ expect that to impact the experience as whole, unless you enabled “formatting on type”, “validation on type”, or both.

As for Terraform itself, there’s still IPC involved when Terraform talks to each plugin/provider (which runs as a separate process). At this point, it seems highly unlikely that this design would change any time soon, but I don’t want to make assumptions as I’m not maintaining [the Core](https://github.com/hashicorp/terraform), or [go-plugin](https://github.com/hashicorp/go-plugin) (the plugin system which effectively implies IPC). Either way though, I would expect this to have relatively minor impact, unless you use _a lot_ of providers (which implies a lot of IPC chattery). In general, I’d assume that more time during `apply` or `destroy` is spent on waiting for the remote APIs to do something (e.g. finish creating a hosted database cluster) rather than waiting for a plugin process to launch.

I do admit, that I have not yet read anything about **why** the IPC is an issue on Windows and what can we do about at as maintainers - aside from not using it and bundling all functionality within the same binary (i.e. either bundling whole LS into Terraform, or re-implementing `validate` and `format` within LS) or nudging more people towards WSL.

I’d welcome any hints and ideas.

> [@marcus](#):
>
> My experience with that was so fiercely painful that I felt I was forced to bring up a WSL environment to run everything in the WSL, except for the VS Code.

FWIW VS Code supports WSL and we’d recommend using it on Windows: [Developing in WSL](https://code.visualstudio.com/docs/remote/wsl)
