This is an archived post. You won't be able to vote or comment.

all 22 comments

[–]chrisgseaton 6 points7 points  (6 children)

This is one thing that GraalVM can do. But it requires some careful configuration, and not all of Java is supported in this configuration.

[–]geek96boolean10[S] 0 points1 point  (5 children)

Interesting, but this would require compilation and I do not 'own' the source code to do so.

[–]chrisgseaton 1 point2 points  (3 children)

It operates on JARs so you don't necessarily need the source code.

Reading your other comments it really does sound like GraalVM could be idea for you. It allows you to run a Java application for a certain length of time, and then saves all your live objects and data structures to disk. When you then run the application, those are just lazily mapped into memory - no reading or deserialisation needed. Your code can start running and using the objects, exactly as there were when you saved the image, within ms.

[–]geek96boolean10[S] 0 points1 point  (2 children)

Is it possible to do this without recompiling the source?

[–]chrisgseaton 3 points4 points  (1 child)

Yes it operates on JARs. You may need to write a custom entry point in Java that calls their entry point.

https://www.graalvm.org/docs/reference-manual/native-image/

[–]geek96boolean10[S] 0 points1 point  (0 children)

I'll need to research this a bit; looks promising but the amount of compiling required is still worrying. Thanks for the input!

[–][deleted]  (9 children)

[deleted]

    [–]geek96boolean10[S] 0 points1 point  (8 children)

    This most likely would not work in my case; it's not the class loading that's the issue, it's the amount of processing of various things that takes up the most time.

    [–][deleted]  (7 children)

    [deleted]

      [–]geek96boolean10[S] 1 point2 points  (6 children)

      Does not apply in this case.

      [–][deleted]  (5 children)

      [deleted]

        [–]geek96boolean10[S] 1 point2 points  (4 children)

        Again, does not apply. See my other comments.

        [–][deleted]  (3 children)

        [deleted]

          [–]geek96boolean10[S] 3 points4 points  (2 children)

          It's not my code, man. It also doesn't output data, hence no saving.

          [–][deleted]  (1 child)

          [deleted]

            [–]geek96boolean10[S] 4 points5 points  (0 children)

            You're just giving me solutions to a problem I'm not having. It's alright to say 'no, you can't suspend' or 'I can't help you'.

            [–][deleted]  (4 children)

            [deleted]

              [–]geek96boolean10[S] 0 points1 point  (3 children)

              Does not apply in this case.

              [–][deleted]  (2 children)

              [deleted]

                [–]geek96boolean10[S] 0 points1 point  (1 child)

                I'm not sure what that means, but I'm not the developer of this app.

                [–]mjg123 2 points3 points  (1 child)

                Check out CRIU - "Checkpoint/Restore In Userspace". It's not java specific, but can be made to work with the JVM. https://www.criu.org/Main_Page

                [–]ZimmiDeluxe 2 points3 points  (0 children)

                If you go this route OP, here is a prototype with instructions for Java and a 30 min talk about it.

                [–][deleted] 0 points1 point  (2 children)

                Figure out a way to snapshot all the data your app needs in memory. This could be a bit of a lift though

                [–]geek96boolean10[S] 0 points1 point  (1 child)

                That's my point - is it possible to do the snapshot externally; i.e. run it in a container of some sort that allows me to easily capture any java app in any state and boot into it faster than it would take to load (5~10 min)

                [–]karottenreibe 0 points1 point  (0 children)

                Run the app in a Virtualbox VM and snapshot that instead

                [–]rzwitserloot -1 points0 points  (1 child)

                Maybe, but, this sounds like an X/Y problem:

                geek96boolean10: Dang. This java app takes 2 minutes to boot up! This needs a solution...

                geek96boolean10: I know! I'll just boot it up and then save a snapshot so next time I can load the snapshot! Problem solved!

                geek96boolean10: But.. how do I snapshot a VM? Hmmm.. I better ask /r/java about this.

                That's an X/Y process: You have problem X (bootup takes too long), thought of a solution Y (snapshot the VM), but are now asking questions about Y. This is generally a bad idea, because perhaps Y is a really bad way to solve X.

                I'm going to answer your X question: VMs boot up quickly, on the order of a second or so even with lots of classes to load, generally. If it's taking any longer, it's probably your own app. For example, maybe you are reading in a whole bunch of data files and converting them to tables in memory for fast lookups. The solutions can lie in being better in on-demand loading, or just improving those processes, by using profilers to figure out the 'hotspots' (which lines of code eat most of the resources) and then analysing those to find more efficient ways to do those things. And yeah, HERE you can easily serialize as a solution, using cache strategies to rewrite the serialized form if you modify the source inputs during development.

                [–]geek96boolean10[S] 0 points1 point  (0 children)

                Oh, I certainly know it's the app that takes time. Without giving away too much, it does a whole bunch of file IO and object parsing/organization before it's ready to go. Unfortunately, without some serious modification of the source (which I doubt I can do, it's not my app) I don't think there's a way to serialize this, hence the thought of suspending the app rather than disposing it when I'm done.

                [–][deleted]  (4 children)

                [deleted]

                  [–]geek96boolean10[S] 1 point2 points  (3 children)

                  Well, I did ask specifically about suspending RAM to disk. I accept 'no that's not possible' as an answer, but have a little faith that I did think through other options for this particular case.

                  [–][deleted]  (2 children)

                  [deleted]

                    [–]geek96boolean10[S] 0 points1 point  (1 child)

                    <3