Fork me on GitHub
#docker
<
2020-06-24
>
jumar04:06:47

@kwladyka I'd try to restrict docker container running on your local host to 60 MB or something like that and see if it still works. When I tried a simple app I couldn't get it work on less than ~130 MB. JVM process consumes much more than just heap memory (see my SO answer with very useful links: https://stackoverflow.com/questions/62303368/accounting-for-java-memory-consumption/62307787#62307787) - e.g. during startup Clojure apps tend to load lots of classes and thus Metaspace consumption will be likely at least 20-30 MB. I didn't notice if you mentioned what JDK you're using and if you tune heap size - see XX:MaxRAMPercentage in particular (70% as mentioned by @lukaszkorecki is a good value in my experience) To sum up: to run anything in prod I'd give it at least 256 MB of ram

👍 3
kwladyka08:06:32

yes, I wanted to try also Metaspace limits, BUT I can’t understand why the same image work on my localhost with 128M and not in google cloud run with 128M or even 256M, it needs 512M

kwladyka08:06:37

@jumar if this wouldn’t work also in my docker, then this will be very clear. I am not able to recreate this.

jumar12:06:31

You may enable gc logging or profile native memory allocations (Native Memory Tracking might be useful) to understand what's going on during startup. Is it correct that the app won't even finish the startup phase?

jumar12:06:51

Now I remember reading about some issues with Virtual memory size - this isn't usually an issue because virtual memory space can be huge with much of it not being allocated at all; therefore what you're typically interested in is the RSS which should more-or-less correspond to the real memory usage (virtual memory pages in RAM). However, some virtualized environments (maybe docker on Google cloud?) empose limits on the total virtual memory size of a process/container. If that's the case your container might be punished although not really using that much memory. But I have no idea if that's applicable to your case. If it runs with 512 MB it might be something completely different

kwladyka13:06:37

Yes, it even doesn’t run first println line in main function. So even not finish load.

jumar13:06:15

Resident Set Size - that's what ps and other tools show you

jumar03:06:17

@kwladyka This is a pure speculation but the "virtual memory" thing I was referring to can be caused by "ulimit" - similar to this: https://stackoverflow.com/questions/44273737/how-to-use-ulimit-with-java-correctly The thing is that ulimit can (on linux) limit only total virtual memory address space. Maybe the google cloud machine has some default for this setting? (it's usually unlimited)

jumar04:06:34

If you have ssh access to the machine you could verify that via :

prlimit --pid PID -v

kwladyka09:06:21

I don’t have ssh access

kwladyka09:06:39

it works with ulimit for me

jumar11:06:03

What do you mean by "it works with ulimit for me"? What exactly you did and where? Did you try gc logging and Native Memory Tracking as I suggested above? What exactly can you do there and how come you don't have access to that machine? I'm afraid that unless you're going to precisely and concisely describe what do you do and what you're seeing you won't get much help. It might also be better suited for general Java/JVM question on StackOverflow. I'm sort running out of ideas based on the limited information I have.

kwladyka13:06:26

ulimit -Sv 131072 to run java -jar foo.jar unless I misunderstood ulimit

kwladyka13:06:41

> What exactly can you do there and how come you don’t have access to that machine? cloud run is very limited. I can only upload docker image. That all what I can do. And observe logs in panel which say nothing in this case.

kwladyka13:06:25

yeah, I was trying to solve this also with guys in google cloud slack and others and nobody can solve this

kwladyka13:06:25

One guy said google cloud use gVisor so it can make a difference. I didn’t have time to try this so far.

kwladyka13:06:41

Alternatively I can also try cloud run Anthos which will add more information maybe

kwladyka13:06:12

these are conclusions which I got from all kinds of slack / community

kwladyka13:06:22

because in theory this shouldn’t happen

kwladyka13:06:36

but for some reason it is happening in cloud run

kwladyka13:06:48

but I have to find time to make tests mentioned above, so far after a few days of debugging I decided to set 512M. It is cheaper than, fix this :/

jumar20:06:03

You tried to run that ulimit on your local machine? If you tried that on your laptop (especiall if it's running Mac OS X) then it might behave differently. I got this error on my Linux server

root@ubuntu-18:/codescene# ulimit -v 131072
root@ubuntu-18:/codescene# java -jar slack-pom.jar
Error occurred during initialization of VM
Could not reserve enough space for code cache
(it's a simple app - look here: https://github.com/curiousprogrammer-net/slack-pom)

kwladyka20:06:08

yes, I was trying this on OS X

jumar20:06:15

That might not have the effect you think it has so it's not really testing anything. Anyway, we would need to know what's the configuration on target machine it doesn't help to compare that with your laptop. And it would likely fail with different error if it was a real problem

jumar20:06:40

What's the java version on used on the server?

kwladyka20:06:37

here is “hello world” example https://github.com/kwladyka/memtest - doesn’t work other branches work

kwladyka20:06:55

Dockerfile has a answer about anvironment

kwladyka20:06:59

I was trying also with v11

kwladyka20:06:11

with buster and scratch

kwladyka20:06:49

https://github.com/kwladyka/memtest/pulls here are examples of changes which make the app work

kwladyka20:06:07

one guy even described process of deployment by code trying to solve this

kwladyka20:06:40

this is not full app, but hello world, but probably the issue is the same

jumar20:06:48

Interesting, it might indeed by an issue with Metaspace sizing - given that when you don't load some of the dependencies it seems to work. You can try adding -XX:+PrintFlagsFinal flag and examine the output

kwladyka20:06:56

I think I was trying but logs didn’t show me that 😞

kwladyka20:06:39

but maybe I am wrong, I was trying to solve this so long, then I can’t be sure

kwladyka20:06:01

I mean the level of tired the topic

kwladyka20:06:43

but it should work with app which is runnable

kwladyka20:06:31

I will try in 10 minutes

kwladyka21:06:47

sorry for the format, it is so hard to copy logs from google

kwladyka21:06:55

hmm MaxMetaSpaceSize looks huge, but I don’t understand why

kwladyka21:06:05

and even if so it should happen, because it shouldn’t take so much memory and works in docker on localhost

kwladyka21:06:49

-XX:MaxMetaspaceSize=30M didn’t solve this

jumar04:06:06

Did you try to set -Xmx explicitly (let's say to 64m)?

jumar10:06:21

If you can you could try to run some monitoring tool alongside the java process, e.g. • _*jstat*_ to monitor heap: `jstat -gc &lt;PID&gt; &lt;repeat-interval-ms&gt;` • _*jcmd &lt;PID&gt; <http://VM.info|VM.info>*_ - very useful (and verbose) info is generated but it takes a while to create; • _*jcmd &lt;PID&gt; VM.native_memory*_ - assuming you start JVM with `-XX:NativeMemoryTracking=summary` or `-XX:NativeMemoryTracking=detail` • _ps_ to monitor RSS • _pmap_ to get much more details about process memory mappings

👍 3
kwladyka10:06:23

I will try but this is not so easy, there is no way to log into shell in cloud run. I was trying to run some commands from Java before.

jumar11:06:10

Could you run multiple processes in your docker container?

kwladyka11:06:17

i can do whatever container can do normally, so AFAIK it is possible but very not recommended

kwladyka11:06:25

but for test purpose should be fine

kwladyka09:06:34

Why use XX:MaxRAMPercentage vs let java (new ver. like 11 / 14 / 15) do what it want?

jumar12:06:12

Because otherwise you'll get only 1/4 of RAM as MaxHeap ("Xmx")

kwladyka20:06:53

Do you mean 1/4 if RAM is default?

kwladyka20:06:42

What is recommended % as default to start with for clojure?

jumar03:06:19

It's my preference but I think 70% is usually ok - but I haven't used it in environments with such restricted RAM capacity; For me it's always 1+ GB of ram available on the machine.

kwladyka13:07:34

Do you know how to run my Java app throw some tool which will give me full debug about memory consumption before memory exceed? I mean I want to see something useful. Running app directly gives me nothing, so I could run app by another app (tool) which will log constantly memory usage. But immediately without delay, because memory exceed kill the container. Any idea ?

kwladyka13:07:13

What is the best solution which you know?