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

Use Class Data Sharing for Java actions #7

Open
rabbah opened this issue Nov 25, 2017 · 1 comment
Open

Use Class Data Sharing for Java actions #7

rabbah opened this issue Nov 25, 2017 · 1 comment

Comments

@rabbah
Copy link
Member

rabbah commented Nov 25, 2017

@alexkli commented on Thu Oct 05 2017

As described in this article, Java has a feature called class data sharing (CDS) that allows to share common class data for different JVMs.

This seems to be available since Java 5 (for JVM & JDK classes), and since Java 8 (u40) support application code as well (AppCDS).

The current OW java action runtime doesn't do anything like that yet.

Benefits:

  • faster JVM startup time: from 120ms to 90ms for a simple hello world program (in that article)
  • reduces memory footprint when running multiple JVMs, apparently works in a containerized environment, should be great within OpenWhisk

There are two steps for the basic CDS AFAICS:

  • prepare the shared class files once via java -Xshare:dump: could be done during the docker image build (?)
  • call the JVM with the flag -Xshare:on to enable CDS (there is some talk about -Xshare:auto becoming the default which I assume would enable it automatically if the prepared files are present)

Leveraging AppCDS in OpenWhisk would mean to include the action Java code, and that might be tricky, as that can only be shared between containers with the same action code IIUC.

Same for Ahead-Of-Time compilation (AOT), new in Java 9, mentioned in the article as well, which has a costly pre-compilation step (that should include the application aka action code), not sure how that could be done within OW. It would be beneficial if an action needs to scale up, i.e. you are starting many new Java containers with a particular action and you want to get the fastest startup time. But maybe pre-warming makes this less useful. One would have to be able to run that action specific pre-compilation up front, and that might require to embed it in the docker image IIUC, which in turn would require building it dynamically from OW, which sounds complex.


@dgrove-oss commented on Thu Oct 05 2017

There should be benefits just from enabling shared classes for the core libraries + framework code (not specific to any user action).


@alexkli commented on Thu Oct 05 2017

Yes, that's what I meant with "basic CDS" (as opposed to AppCDS). It could include the java action framework code.


@rabbah commented on Thu Oct 05 2017

The Java runtime is moving to a new repository - when that's complete, we'll move this issue there.

FYI @csantanapr.

@Param-S
Copy link
Contributor

Param-S commented Mar 1, 2018

Effect of CDS on startup and memory.

Startup time measure by capturing timestamp before invoking the Java command & after server started up. Like

in Dockerfile:

 ///CMD ["java", "-jar", "/javaAction/build/libs/javaAction-all.jar"]
CMD ["/bin/bash", "/javaAction/run.sh"]

in run.sh:

date +%H:%M:%S:%N-%Z   /* capture the time before invoking java command */
java -jar /javaAction/build/libs/javaAction-all.jar

in Proxy.java:

    public void start() {
        server.start();
                  **/* capture the time after the Http server start */**
                  ZoneId zoneId = ZoneId.of("UTC");
                 ZonedDateTime ctime = ZonedDateTime.now(zoneId);
                 System.out.println(ctime.toString());
    }

With this change, I measured the startup time for 50 iterations & server starts up faster with CDS which is evident from the below graph.

screen shot 2018-03-01 at 4 38 06 pm

Memory Usage:

CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
388eea3db27f        Xshare       0.11%               17.95MiB / 15.67GiB   0.11%               648B / 0B           0B / 4.1kB          23
16482b3afcc5        Default      0.13%               19.56MiB / 15.67GiB   0.12%               648B / 0B           0B / 4.1kB          23

Opened PR #21 to enable CDS.

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

No branches or pull requests

2 participants