Skip to content

Commit 4998ed7

Browse files
yaohui-wyhrogeryhwang
authored and
rogeryhwang
committed
[jb] configure vmoptions for intellij backend server performance optimization
1 parent 177ec6e commit 4998ed7

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

components/ide/jetbrains/image/leeway.Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ RUN apk add --no-cache --upgrade curl gzip tar unzip
99
RUN curl -sSLo backend.tar.gz "$JETBRAINS_BACKEND_URL" && tar -xf backend.tar.gz --strip-components=1 && rm backend.tar.gz
1010
COPY --chown=33333:33333 components-ide-jetbrains-backend-plugin--plugin/build/distributions/gitpod-remote-0.0.1.zip /workdir
1111
RUN unzip gitpod-remote-0.0.1.zip -d plugins/ && rm gitpod-remote-0.0.1.zip
12-
RUN printf '\n-Dgtw.disable.exit.dialog=true\n' >> $(find /workdir/bin/ -name "*64.vmoptions")
1312
# enable shared indexes by default
1413
RUN printf '\nshared.indexes.download.auto.consent=true' >> "/workdir/bin/idea.properties"
1514

components/ide/jetbrains/image/status/main.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ func main() {
9191
if err != nil {
9292
log.WithError(err).Error("failed to configure backend Xmx")
9393
}
94+
err = configureVMOptions(alias)
95+
if err != nil {
96+
log.WithError(err).Error("failed to configure vmoptions")
97+
}
9498
go run(wsInfo, alias)
9599

96100
http.HandleFunc("/joinLink", func(w http.ResponseWriter, r *http.Request) {
@@ -322,6 +326,35 @@ func configureXmx(alias string) error {
322326
return ioutil.WriteFile(launcherPath, []byte(newContent), 0)
323327
}
324328

329+
func configureVMOptions(alias string) error {
330+
idePrefix := alias
331+
if alias == "intellij" {
332+
idePrefix = "idea"
333+
}
334+
// [idea64|goland64|pycharm64|phpstorm64].vmoptions
335+
path := fmt.Sprintf("/ide-desktop/backend/bin/%s64.vmoptions", idePrefix)
336+
content, err := ioutil.ReadFile(path)
337+
if err != nil {
338+
return err
339+
}
340+
newContent := updateVMOptions(alias, string(content))
341+
return ioutil.WriteFile(path, []byte(newContent), 0)
342+
}
343+
344+
func updateVMOptions(alias string, content string) string {
345+
var newContent = content
346+
// 1. replace -Xmx with -XX:MaxRAMPercentage (when env var set)
347+
maxRAM := os.Getenv(strings.ToUpper(alias) + "_MaxRAMPercentage")
348+
if maxRAM != "" {
349+
re := regexp.MustCompile(`-Xmx(\d+)([MmGg])`)
350+
newContent = re.ReplaceAllString(newContent, "-XX:MaxRAMPercentage="+maxRAM)
351+
fmt.Println(newContent)
352+
}
353+
// 2. disable the exit dialog
354+
newContent += "\n-Dgtw.disable.exit.dialog=true"
355+
return newContent
356+
}
357+
325358
/**
326359
{
327360
"buildNumber" : "221.4994.44",

components/ide/jetbrains/image/status/main_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,29 @@ func TestGetProductConfig(t *testing.T) {
2323
t.Errorf("unexpected output (-want +got):\n%s", diff)
2424
}
2525
}
26+
27+
func TestUpdateVMOptions(t *testing.T) {
28+
tests := []struct {
29+
Desc string
30+
Alias string
31+
EnvVar map[string]string
32+
Src string
33+
Expectation string
34+
}{
35+
{"goland64.vmoptions", "goland", nil, "-Xms128m\n-Xmx750m\n-Dsun.tools.attach.tmp.only=true", "-Xms128m\n-Xmx750m\n-Dsun.tools.attach.tmp.only=true\n-Dgtw.disable.exit.dialog=true"},
36+
{"idea64.vmoptions", "intellij", nil, "-Xms128m\n-Xmx750m\n-Dsun.tools.attach.tmp.only=true", "-Xms128m\n-Xmx750m\n-Dsun.tools.attach.tmp.only=true\n-Dgtw.disable.exit.dialog=true"},
37+
{"idea64.vmoptions (MaxRAMPercentage env set)", "intellij", map[string]string{"INTELLIJ_MaxRAMPercentage": "50"}, "-Xms128m\n-Xmx2048m\n-Dsun.tools.attach.tmp.only=true", "-Xms128m\n-XX:MaxRAMPercentage=50\n-Dsun.tools.attach.tmp.only=true\n-Dgtw.disable.exit.dialog=true"},
38+
{"idea64.vmoptions (MaxRAMPercentage env set)", "intellij", map[string]string{"INTELLIJ_MaxRAMPercentage": "75"}, "-Xms128m\n-Xmx2g\n-Dsun.tools.attach.tmp.only=true", "-Xms128m\n-XX:MaxRAMPercentage=75\n-Dsun.tools.attach.tmp.only=true\n-Dgtw.disable.exit.dialog=true"},
39+
}
40+
for _, test := range tests {
41+
t.Run(test.Desc, func(t *testing.T) {
42+
for v := range test.EnvVar {
43+
t.Setenv(v, test.EnvVar[v])
44+
}
45+
actual := updateVMOptions(test.Alias, test.Src)
46+
if diff := cmp.Diff(test.Expectation, actual); diff != "" {
47+
t.Errorf("unexpected output (-want +got):\n%s", diff)
48+
}
49+
})
50+
}
51+
}

0 commit comments

Comments
 (0)