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

[jb] configure vmoptions for intellij backend server #10175

Merged
merged 1 commit into from
Jun 13, 2022

Conversation

yaohui-wyh
Copy link
Contributor

@yaohui-wyh yaohui-wyh commented May 22, 2022

Description

  1. Specify JVM max heap usage with -XX:MaxRAMPercentage (follows jb: java perf monitoring #9796 ) for better resource usage in a containerized env
  2. Move all vmoptions customizations into /ide-desktop/status and make it easier for future vmoptions optimizations

Related Issue(s)

Related #8704

How to test

Test manually at #8704 (comment)

Release Notes

- Allow customize VMOptions for JetBrains backend server, by setting `INTELLIJ_VMOPTIONS` (also GoLand/PyCharm/PhpStorm) environment variable

Documentation

@akosyakov
Copy link
Member

akosyakov commented May 22, 2022

Maybe we should look into more generic solution to allow customisations for different JVMs than introducing an env var for everything? Maybe we could use one env var instead like [option]_VM_OPTIONS? [option]_XMX makes sense to have separate only because it treated specially by launcher script. Could you have look at launcher script maybe there is already such env var and rather we are missing better docs?

@yaohui-wyh
Copy link
Contributor Author

Maybe we should look into more generic solution to allow customisations for different JVMs than introducing an env var for everything? Maybe we could use one env var instead like [option]_VM_OPTIONS? [option]_XMX makes sense to have separate only because it treated specially by launcher script. Could you have look at launcher script maybe there is already such env var and rather we are missing better docs?

I looked into remote-dev-server.sh, launcher.sh, idea.sh, and extract the logic involving how VMOptions is passed to the Java process (intellij server) across all the wrapper scripts:

# 1. remote-dev-server.sh
launcher.sh "idea.sh" "IU" "IDEA" "idea" "-Xmx750m" "$@"

# 2. launcher.sh
# note that "idea" (idea64.vmoptions) and "-Xmx750m" below are passed by remote-dev-server.sh
TEMP_VM_OPTIONS=$IJ_HOST_SYSTEM_DIR/pid.$$.temp.vmoptions
cp idea64.vmoptions $TEMP_VM_OPTIONS
sed "s/-Xmx750m/-Xmx2048m/g" ... > $TEMP_VM_OPTIONS

# export for idea.sh
IDEA_VM_OPTIONS=$TEMP_VM_OPTIONS 

# 3. idea.sh
VM_OPTIONS_FILE=$IDEA_VM_OPTIONS                       
VM_OPTIONS=`cat $VM_OPTIONS_FILE`
java ${VM_OPTIONS} com.intellij.idea.Main ...

And here are some thoughts:

  1. User customization to JVM arguments should be written to idea64.vmoptions (for desktop IntelliJ IDEs, customization also happens to idea64.vmoptions or similar vmoptions files such as from Toolbox).
  2. Besides the -Xmx, all other JVM arguments are treated equal for remote server. And if user has modified the -Xmx, launcher.sh does nothing.

Suggestions:

  1. If we want to modify the default JVM args in case of performance tuning (or to allow Gitpod users overwriting the default value), better modify the idea64.vmoptions than launcher.sh (thus configureXmx needs update).
  2. Provide a single [alias]_VMOPTIONS env var which allows a list of arguments separated by space (which is nature to Java Options), and no separated [alias]_XMX
jetbrains:
  // default for all
  vmoptions: "-XX:MaxRAMPercentage=50.0 -Dgtw.disable.exit.dialog=true" 
  intellij:
    // override or prepend -Xmx for intellij
    vmoptions: "-Xmx6g" 
  goland:
    // override or prepend -Xmx for goland
    vmoptions: "-Xmx4096m" 

@akosyakov
Copy link
Member

It sounds good

@yaohui-wyh
Copy link
Contributor Author

yaohui-wyh commented May 24, 2022

I've updated the changes. PTAL again @akosyakov 🙏

During the VMOptions investigation I wrote a post about the bootstrap process of a IntelliJ IDE workspace:
https://spurious-amount-763.notion.site/Gitpod-workspace-with-JetBrains-Gateway-a78f71c39c364ab8ba90ed3ac5ec9643

@akosyakov
Copy link
Member

@iQQBot do you think you can help @yaohui-wyh how to setup self-hosted solution to test PRs?

@iQQBot
Copy link
Contributor

iQQBot commented May 24, 2022

@iQQBot do you think you can help @yaohui-wyh how to setup self-hosted solution to test PRs?

I can help if you need @yaohui-wyh

@yaohui-wyh
Copy link
Contributor Author

yaohui-wyh commented Jun 10, 2022

I test the PR on Gitpod SaaS. PTAL @akosyakov 🙏


The test plan is to use a Gitpod workspace (with intellij backend server) to build the status binary and replace the /ide-desktop/status, and kill the status process from the workspace (supervisor would restart the status process), then the main logic can be tested in-place

  1. Choose IntelliJ as the default editor https://gitpod.io/preferences
  2. Add envvar INTELLIJ_VMOPTIONS, such as -XX:MinRAMPercentage=25 -Xmx3g
  3. Start Gitpod workspace from this PR: https://gitpod.io/#https://github.com/gitpod-io/gitpod/pull/10175
  4. Launch a new Terminal and build the status binary: cd /workspace/gitpod/components/ide/jetbrains/image/status && go build (maybe better with leeway build ... <some args>)
  5. Replace the status binary: rm /ide-desktop/status; cp status /ide-desktop/status
  6. Check the IDE server Java Process VMOptions: jps -ml | grep intellij; jinfo <pid> > ~/jinfo1.txt
  7. Kill the status process: ps aux | grep status; kill -9 <pid>
  8. (Supervisor restart status process), and check step7 again: jps -ml | grep intellij; jinfo <pid> > ~/jinfo2.txt

Expected behavior:

  1. jinfo2.txt (Step7) should contain VMOptions set by envvar (Step2), and no other VMOptions are touched
  2. Connect to Gitpod workspace via Gateway, check the "backend control center" from JBThinClient, and the Maximum heap size should be 3GiB

image

image

image

p

func updateVMOptions(alias string, content string) string {
// inspired by how intellij platform merge the VMOptions
// https://github.com/JetBrains/intellij-community/blob/master/platform/platform-impl/src/com/intellij/openapi/application/ConfigImportHelper.java#L1115
filterFunc := func(l, r string) bool {
Copy link
Member

Choose a reason for hiding this comment

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

why it is not part of deduplicateVMOption?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To make it easier to have finer control over the type of VMOptions to dedup. Currently, only memory-related VMOptions (-Xmx / -Xms, etc.) are handled, however, if we need to deal with VMOptions such as GC-related by another feature toggle (e.g. a separate env var). Putting all filter logic into deduplicateVMOption is a bit messy.

It's similar to updateVMOptions (https://github.com/JetBrains/intellij-community/blob/master/platform/platform-impl/src/com/intellij/openapi/application/ConfigImportHelper.java#L1068) from the Intellij codebase

@akosyakov
Copy link
Member

akosyakov commented Jun 13, 2022

/werft run

👍 started the job as gitpod-build-local-fork.1
(with .werft/ from main)

Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

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

/lgtm

@akosyakov
Copy link
Member

@yaohui-wyh Do you want to add it to .gitpod.yml?

@roboquat roboquat merged commit 49224d1 into gitpod-io:main Jun 13, 2022
@yaohui-wyh
Copy link
Contributor Author

@yaohui-wyh Do you want to add it to .gitpod.yml?

Hi Anton! Do you mean adding to .gitpod.yml user document how to customize VMOptions for Gateway? Or modify the .gitpod.yml of some JB Gateway demo projects such as gitpod-io/spring-petclinic?

@akosyakov
Copy link
Member

Hi Anton! Do you mean adding to .gitpod.yml user document how to customize VMOptions for Gateway? Or modify the .gitpod.yml of some JB Gateway demo projects such as gitpod-io/spring-petclinic?

I mean first adding it to gitpod.yml schema and actually making use of it. Then everything else.

@yaohui-wyh
Copy link
Contributor Author

I mean first adding it to gitpod.yml schema and actually making use of it. Then everything else.

Thanks, I get it. Yeah I would add the vmoptions config to gitpod-config-type (according to this reply #10175 (comment))

One thing to mention, I think users can already make use of it now by specifying variables for a project. However, add the option to project-wide .gitpod.yml config does give users more flexibility.

@akosyakov
Copy link
Member

One thing to mention, I think users can already make use of it now by specifying variables for a project. However, add the option to project-wide .gitpod.yml config does give users more flexibility.

.gitpod.yml is to share across all users of the project, it can be overridden by user env vars

@roboquat roboquat added deployed: IDE IDE change is running in production deployed Change is completely running in production labels Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: accepted ✔️ community-contribution deployed: IDE IDE change is running in production deployed Change is completely running in production release-note size/L team: IDE
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants