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

Consider launching dockerized cljdoc from jar #491

Open
lread opened this issue Jan 20, 2022 · 2 comments
Open

Consider launching dockerized cljdoc from jar #491

lread opened this issue Jan 20, 2022 · 2 comments

Comments

@lread
Copy link
Member

lread commented Jan 20, 2022

Currently

Cljdoc is launched in production within its docker container via clojure.

Idea

Instead, launch cljdoc from a stand alone jar via java.

Why?

Faster startup time in production, but perhaps more interesting, faster times when using running cljdoc locally via docker.

I did a wee adhoc test from the command line (not involving docker).
I wait about 15s until first log line output when launching via:

clojure -M -m cljdoc.server.system

Versus about 5s to first log line output when launching via a prebuilt stand-alone jar which in my local test was via:

java -jar target/cljdoc-1.2.3-leetest-standalone.jar

This jar was built via the following quickly-hacked-together build.clj:

(ns build
  (:require [clojure.tools.build.api :as b]))

(def lib 'cljdoc/cljdoc)
(def version "1.2.3-leetest")
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn" :aliases [:cli]}))
(def uber-file (format "target/%s-%s-standalone.jar" (name lib) version))

(defn clean [_]
  (b/delete {:path "target"}))

(defn uber [_]
  (clean nil)
  (b/copy-dir {:src-dirs ["src" "resources" "resources-compiled"]
               :target-dir class-dir})
  (b/compile-clj {:basis basis
                  :src-dirs ["src"]
                  :class-dir class-dir})
  (b/uber {:class-dir class-dir
           :uber-file uber-file
           :basis basis
           :main 'cljdoc.server.system}))

Impacts

We currently support running cljdoc locally via the production cljdoc docker image.

This can use a different main entry point than the production server launch does, for example for ingesting local docs.

As far I understand things, a jar only easily supports a single main entry point.

So, if we entertained this change, we'd likely move to a single main entry point.

Whatcha think?

I'm sure I haven't thought of a thing or two, happy to hear what you, dear reader, think.

@lread
Copy link
Member Author

lread commented Apr 6, 2022

Or... maybe look at jlink and CDS for launch speed.

This would add some complexity to the docker build so we'd have to measure the benefit.

@lread
Copy link
Member Author

lread commented Feb 9, 2023

Of interest, you can invoke multiple different mains from a jar by using -cp instead of -jar.

Nic example from @seancorfield on slack:

(~/clojure/mains)-(!2016)-> cat src/multi/another.clj
(ns multi.another
  (:gen-class))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "I'm another main!"))

Thu Feb 09 11:18:09
(~/clojure/mains)-(!2017)-> cat src/multi/mains.clj
(ns multi.mains
  (:gen-class))

(defn greet
  "Callable entry point to the application."
  [data]
  (println (str "Hello, " (or (:name data) "World") "!")))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (greet {:name (first args)}))

Thu Feb 09 11:18:12
(~/clojure/mains)-(!2018)-> java -jar target/net.clojars.multi/mains-0.1.0-SNAPSHOT.jar
Hello, World!

Thu Feb 09 11:18:22
(~/clojure/mains)-(!2019)-> java -jar target/net.clojars.multi/mains-0.1.0-SNAPSHOT.jar argument
Hello, argument!

Thu Feb 09 11:18:28
(~/clojure/mains)-(!2020)-> java -cp target/net.clojars.multi/mains-0.1.0-SNAPSHOT.jar multi.mains
Hello, World!

Thu Feb 09 11:18:48
(~/clojure/mains)-(!2021)-> java -cp target/net.clojars.multi/mains-0.1.0-SNAPSHOT.jar multi.mains argument
Hello, argument!

Thu Feb 09 11:18:52
(~/clojure/mains)-(!2022)-> java -cp target/net.clojars.multi/mains-0.1.0-SNAPSHOT.jar multi.another
I'm another main!

Thu Feb 09 11:19:02
(~/clojure/mains)-(!2023)->

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

1 participant