Welcome! Please see the About page for a little more info on how this works.

0 votes
in Namespaces and vars by
edited by

Our server is experiencing memory leaking. As to investigate what happened, I used jmap to dump JVM and got the following file:

No dump file specified
 num     #instances         #bytes  class name (module)
-------------------------------------------------------
   1:        904887       79630056  java.lang.reflect.Method (java.base@13.0.2)
   2:        935204       50874608  [Ljava.lang.Object; (java.base@13.0.2)
   3:        889710       47099400  [B (java.base@13.0.2)
   4:         85795       26006880  [C (java.base@13.0.2)
   5:        518846       22286056  [I (java.base@13.0.2)
   6:        781108       18746592  java.lang.String (java.base@13.0.2)
   7:        382891       15315640  java.math.BigInteger (java.base@13.0.2)
   8:        370774       14830960  java.math.BigDecimal (java.base@13.0.2)
   9:        153329       12266320  java.lang.reflect.Constructor (java.base@13.0.2)
...
 152:          1665         146520  java.util.regex.Pattern (java.base@13.0.2)
 153:          3638         145520  com.newrelic.agent.deps.org.objectweb.asm.tree.LdcInsnNode
 154:          9043         144688  exchange.api.restful.orders$fn__48874$fn__48879
 155:          9043         144688  exchange.api.restful.orders$fn__48874$fn__48881
 156:          9043         144688  exchange.api.restful.orders$fn__48874$fn__48883
 157:          9043         144688  exchange.api.restful.orders$fn__48874$fn__48885
 158:          9043         144688  exchange.api.restful.orders$fn__48874$fn__48887
 159:          9043         144688  exchange.api.restful.orders$fn__48874$fn__48892
 160:          9006         144096  java.util.Formatter$Flags (java.base@13.0.2)
 161:          8973         143568  java.util.concurrent.atomic.AtomicBoolean (java.base@13.0.2)
...
 600:           296           7104  java.math.MathContext (java.base@13.0.2)
 601:           221           7072  java.lang.invoke.BoundMethodHandle$Species_L (java.base@13.0.2)
 602:           221           7072  java.lang.invoke.LambdaForm$NamedFunction (java.base@13.0.2)
 603:           438           7008  clojure.core$distinct$step__6413
 604:           291           6984  taoensso.nippy$read_kvs_into$fn__36561
 605:           218           6976  sun.nio.fs.UnixPath (java.base@13.0.2)
 606:           218           6976  taoensso.carmine.protocol.EnqueuedRequest
 607:           173           6920  java.nio.channels.ClosedChannelException (java.base@13.0.2)
 608:           431           6896  clojure.core.async.impl.ioc_macros$return_chan$fn__21752
 609:           287           6888  javax.management.ImmutableDescriptor (java.management@13.0.2)
...

So as you might interpret from it, it is an API service. And judging from the number of instances, I decided exchange.api.restful.orders$fn__48874$* is bad. (Or I am wrong. My colleague suggested redis went wrong.)

But here then goes the question: which function/api is it? How can I locate it?

1 Answer

+1 vote
by
selected by
 
Best answer

Try using (fn some-name [] ...) instead of (fn [] ...) or #(...).

by
Actually, the endpoints looks like (using `ring` and `compojure`)

```clojure
(defroutes plus
  (GET "/plus" []
    :return {:result Long}
    :query-params [x :- Long, y :- Long]
    :summary "adds two numbers together"
    (ok {:result (+ x y)})))
```

So I am not sure where to add the function name.
by
Maybe extract `(+ x y)` to a function, e.g. `(defn add [x y] (+ x y))` and use `(ok {:result (add x y)})`. It's `compojure-api`, not `compojure`... never used it, not sure how it works. If it doesn't work, try monitoring `(+ x y)` parts individually, for each suspicious endpoint. You can use https://github.com/clojure-goes-fast/clj-memory-meter from the REPL.
...