Docker single executable / memory consumption
predaytor opened this issue · 7 comments
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"]
Will this be possible with the release of Deno 2.1.0?
To include files or directories in the executable, specify them via the
--include <path>
flag.deno compile --include names.csv --include data main.tsThen 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 hereNote this currently only works for files on the file system and not remote
files.
@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 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();
}
on Canary it's about ~370 MB of memory consumption, in addition to static files and routes not working.
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.
upd: it's a canary version
also, let me try the canary version later