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

Docker single executable / memory consumption #2757

Open
predaytor opened this issue Nov 12, 2024 · 7 comments
Open

Docker single executable / memory consumption #2757

predaytor opened this issue Nov 12, 2024 · 7 comments

Comments

@predaytor
Copy link

Is it possible to reduce memory consumption with Fresh 2.0? Currently deployed on fly.io on a 1024MB machine, while a similar application on Node.js consumes around 190-220MB of RAM. Maybe we can create a single executable and get rid of typescript transpilation at runtime? Very thanks.

FROM denoland/deno:debian

WORKDIR /app

COPY . .

RUN deno task build

EXPOSE 80

CMD ["run", "-A", "main.ts"]
@predaytor
Copy link
Author

Will this be possible with the release of Deno 2.1.0?

denoland/deno#26939

To include files or directories in the executable, specify them via the --include <path> flag.

deno compile --include names.csv --include data main.ts

Then read the file relative to the directory path of the current module via import.meta.dirname:

// main.ts
const names = Deno.readTextFileSync(import.meta.dirname + "/names.csv");
const dataFiles = Deno.readDirSync(import.meta.dirname + "/data");

// use names and dataFiles here

Note this currently only works for files on the file system and not remote
files.

@janjangao
Copy link

@predaytor hi, I think since Deno 2.1.3, --include <path> shall work correctly with deno compile

You can compile the fresh app with single executable file then copy and run in a low memory environment. Can take reference of my Dockerfile
https://github.com/janjangao/hayond.site/blob/main/Dockerfile

@janjangao
Copy link

You can compile the fresh app with single executable file then copy and run in a low memory environment.

But there is an other issue, I can see a simple fresh app with 50M at initial state, but the memory increase little by little when day goes by, maybe there's potential memory leak problem.

image

@predaytor
Copy link
Author

predaytor commented Dec 13, 2024

@janjangao interesting. for some reason I am getting "Not Found" for my routes. The directly described API endpoints (GET/POST) are working properly:

upd: it's a canary version

import { App, fsRoutes, staticFiles, trailingSlashes } from 'fresh';
import { satoriApi } from '~/api/satori.tsx';
import { subscribeApi } from '~/api/subscribe.ts';
import { cors } from '~/middleware/cors.ts';
import { secureHeaders } from '~/middleware/security-headers.ts';

export const app = new App<State>({ root: import.meta.url });

app.use(staticFiles());
app.use(trailingSlashes('never'));
app.use(cors);
app.use(secureHeaders);

app.post('/api/subscribe', subscribeApi);
app.get('/api/satori', satoriApi);

await fsRoutes(app, {
    dir: './',
    loadIsland: (path) => import(`./islands/${path}`),
    loadRoute: (path) => import(`./routes/${path}`),
});

if (import.meta.main) {
    await app.listen();
}

@predaytor
Copy link
Author

on Canary it's about ~370 MB of memory consumption, in addition to static files and routes not working.

@janjangao
Copy link

for some reason I am getting "Not Found" for my routes.

oh, I didn't write complex logic like this, maybe let me proceed try my webside to see if have same issue.

@janjangao
Copy link

upd: it's a canary version

also, let me try the canary version later

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