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

Pass args on JVM startup #72

Closed
adriendengreville opened this issue May 26, 2020 · 14 comments · Fixed by #287
Closed

Pass args on JVM startup #72

adriendengreville opened this issue May 26, 2020 · 14 comments · Fixed by #287
Labels

Comments

@adriendengreville
Copy link

Hi !

I'm hitting the 8G memory limit and wanted to pass the -Xmx startup flag but couldn't find how to it. I believe it's useful to be able to customize how the JVM starts up.
I'm not familiar with Jupyter's internals, but is this where the args should be passed ?

subprocess.call(['java', '-jar'] + debug_list +

Or should we pass them somewhere else ?

Cheers !

PS : If you have any tips on how to change the memory limit, I'm still interested :)

@ileasile
Copy link
Collaborator

ileasile commented May 27, 2020

Hi! Actually yes, you should have run_kernel.py file as a part of your kernel installation. And there, you may add any java arguments. In your case it will be ['java', '-Xmx=8G', '-jar'], and so on

@ileasile ileasile reopened this May 27, 2020
@adriendengreville
Copy link
Author

adriendengreville commented May 27, 2020

Thanks, this workaround will do the trick in my case !
Do you think there is a way to specify this from the notebook rather than by tweaking the kernel ?
Something like having a KERNEL_JAVA_OPTS env var used like ['java', '$KERNEL_JAVA_OPTS, '-jar'] ?
But I don't know if we can specify/populate env vars from the notebook before the kernel starts, though

@ileasile
Copy link
Collaborator

I agree that this way is ugly and inconvinient. We will think about simplifying it, but I'm not sure that specifying options in notebook will work - it requires tweaking kernel connecting process. Thank you for pointing to this problem!

@jbaron
Copy link
Contributor

jbaron commented Jun 18, 2021

Would also like the option to somehow influence the heap allocation without having users having to modify the kernel startup parameters. I see two options:

  1. Install several Kotlin kernels with only different hard-coded param for max heap size and call them for example "Small Memory Koltin", "Mid Memory Kotlin" and "Large Memory Koltin". This is easy and users can before they start a notebook, pick the appropriate kernel. However if we also want to offer for example different JVM versions, this quickly becomes a large set of options and each requires a separate pip install with its own package I guess.

  2. Allow to user to specify the runtime (the Google Colab approach for GPU/TPU config). This is more flexible but not sure this can be added as a plug-in to Jupyter (via pip) or requires a fork and different Jupyter installation all together. But would be nice to have something like this in Datalore.

@rnett
Copy link
Contributor

rnett commented Jun 29, 2021

It's easy enough to parameterize based on an environment variable or config file in the kernelspec, which does require a separate kernel, but not a separate pip/conda package. See #287.

I can PR something for it after #287, I would do it by adding an environment variable and a jvmArgs parameter to the JDK kernel generation task (and maybe renaming it).

@rnett
Copy link
Contributor

rnett commented Jun 29, 2021

I haven't tested this, but I would think you could do something like KOTLIN_JUPYTER_JVM_ARGS=whatever jupyter-lab once that's supported.

@jbaron
Copy link
Contributor

jbaron commented Jun 29, 2021

If I understand correctly, that doesn't allow an normal end-user (so using a web-browser to access a notebook) to select a certain JVM heap size. For example this wouldn't allow me to select a different heap-size on datalore.

@rnett
Copy link
Contributor

rnett commented Jun 29, 2021

I think you could set it via a secret, but regardless you'd need some sort of UI either in datalore or jupyter. Said UI would use the environment variable to pass it to the kernel.

@jbaron
Copy link
Contributor

jbaron commented Jun 30, 2021

For my use-case I would prefer that in the kernel.json I can optionally specify JVM parameters that would be used by the run_kernel.py when starting the JVM. So similar how this was solved for IJava:

Default:

{
    "display_name": "Kotlin",
    "language": "kotlin",
    "interrupt_mode": "message",
    "argv": [
        "python",
        "-m",
        "run_kotlin_kernel",
        "{connection_file}"
    ]
}

Added JVM options:

{
    "display_name": "Kotlin Large",
    "language": "kotlin",
    "interrupt_mode": "message",
    "argv": [
        "python",
        "-m",
        "run_kotlin_kernel",
        "-jvm", "-Xmx8G"
        "{connection_file}"
    ]
}

So the change would only be in run_kernel that would check for the -jvm argument being provided and if so add it to the startup command of the JVM.

@rnett
Copy link
Contributor

rnett commented Jun 30, 2021

You can do that just fine with environment variables, in fact that's how I'm creating JVM kernels. Something like:

{
    "display_name": "Kotlin",
    "language": "kotlin",
    "interrupt_mode": "message",
    "argv": [
        "python",
        "-m",
        "run_kotlin_kernel",
        "{connection_file}"
    ],
    "env": {
        "KOTLIN_JUPYTER_JVM_ARGS": "-Xmx8G"
    }
}

Would that work for you?

@jbaron
Copy link
Contributor

jbaron commented Jun 30, 2021

Yes :) I wrongly assumed env variables are the ones set at shell level (and not kernel.json). But this is perfect. I now just need to create few kernel.json files with different display names and env settings and end-user can select the kernel he/she wants to use.

@rnett
Copy link
Contributor

rnett commented Jun 30, 2021

Yeah, the settings in kernel.json override the current shell env.

@nlhnt
Copy link

nlhnt commented Mar 15, 2022

Could we get some simple example in readme.md that could show where to locate and how to change the configuration file?
Reading this thread I am not sure if setting up some env variables fixes the problem or not.
Not sure if I have to clone the repository and change the config before installing the kernel?
I guess that setting can be found in:
(...)/anaconda3/pkgs/kotlin-jupyter-kernel-0.11.0.61-py_0/share/jupyter/kernels/kotlin/, that's not obvious to a user when trying out the library and then getting hit with heap size error when loading a testing CSV.

@jbaron
Copy link
Contributor

jbaron commented Mar 15, 2022

Not sure what config you are looking for (and fully agree we need more doc), but this is what I use to add kernels with different JVM settings:

python -m kotlin_kernel add-kernel --name "XLARGE 16GB" --jvm-arg=-Xmx16G

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants