nanovms / nanos

A kernel designed to run one and only one application in a virtualized environment
https://nanos.org
Apache License 2.0
2.58k stars 133 forks source link

Scheduled Task Stops Prematurely in Java in Firecracker MicroVM #2025

Closed Roopsai507 closed 2 months ago

Roopsai507 commented 3 months ago

I have a Java program that schedules a periodic task to run every 10 seconds using a ScheduledExecutorService. When I run the program locally using ops deploy, it works fine, and the task executes as expected, printing a message every 10 seconds.

However, when I start the same program in a Firecracker MicroVM, the scheduler stops after executing the task only 5 to 6 times.

Code Snippet :

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class PeriodicTaskExample {
    public static void main(String[] args) {
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
        // Schedule the task to run every 10 seconds
        executorService.scheduleAtFixedRate(() -> {
            try {
                System.out.println("Periodic task executed");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, 0, 10, TimeUnit.SECONDS);

        // Keeping the main thread alive indefinitely
        try {
            Thread.sleep(Long.MAX_VALUE);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

Firecracker Version : 1.6.0 Ops Kernel image : d9743ea Java Package : java_1.8.0_191

eyberg commented 3 months ago

i looked into this briefly using slightly diff. more-up-to-date versions and wasn't reproducing

I tried w/ Firecracker v1.7.0 && eyberg/java:20.0.1 on nanos nightly

can you try w/that and see if you're still seeing what you see?

Roopsai507 commented 2 months ago

Have tried with Firecracker v1.7.0 && eyberg/java:20.0.1 Ops Kernel image : d9743ea

Still i am facing the same issue.

eyberg commented 2 months ago

can you paste a log of '--trace' running here - perhaps we might see what you are hitting?

also since you state that it works fine w/qemu/ops can you show us

cat /proc/cpuinfo  | grep model.name
cat /etc/lsb-release
uname -a

firecracker by default has a lot of capabilities toggled by default, idk what you might be hitting there but that might be something to look at

also - can you tell us where you are running this? in the cloud? locally? inside of another vm?

Roopsai507 commented 2 months ago

The issue was resolved when I reinstalled my machine with a higher kernel version. Previously I was using a physical machine with

Kernel-Version : 3.10.0-1160.6.1.el7.x86_64
Os: CentOS 7

Then I changed it to

Kernel-Version: 5.10.178
Os: Debian 11 (bullseye)

It was working fine after this