Why is my Dart server getting Killed with less than 100% memory usage?

75 views Asked by At

My server is Ubuntu x86_64 with a basic package of Digitalocean.

Dart --version: Dart SDK version: 3.0.5 (stable) (None) on "linux_x64"
CPU Type: Premium Intel
vCPUs: 1 vCPU
Memory: 1 GB
SSD: 25 GB
Transfer: 1 TB

After I update my code and deploy it to the server, I got Killed in the console after using dart run ....

I check the resource that was used by Dart by using the top command. The dart running at starting is using CPU = ~99% and Memory = ~45-50% (Other processes are using memory lower than 15%).

After this, I tried to run my Dart server with a basic code like this.

Future main(List<String> arguments) async {
  final cascade = Cascade().add(_staticHandler).add(_router);
  final server = await shelf_io.serve(logRequests().addHandler(cascade.handler), InternetAddress.anyIPv4, 8080);
  print('\nServer is running\naddress:${server.address.address}\nhost:${server.address.host}\nport: ${server.port}\n');
}
final _staticHandler = shelf_static.createStaticHandler('folder', defaultDocument: 'index.html');
final _router = shelf_router.Router();

When I run this code above, the server will be running fine. The CPU usage is ~99% and memory usage is ~30%. So, I think the CPU was used not the cause of this because it is the same value.

The cause is memory used right? but it is just 45-50% of the 100%. Why I got Killed after running the dart server on Ubuntu?

In the local(my computer) everything works fine.

I had asked like this post before (Question). But this memory used by the dart server is not 100% it is just ~50%. What is the real cause?

1

There are 1 answers

0
Sittiphan Sittisak On BEST ANSWER

After I tried to import my routes one by one. I found that some files in my server are using a package of the flutter side like universal_html. This is the cause of my issue. After I remove it, my server can run fine.