docker

jumar 2020-06-24T04:05:47.089200Z

@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

👍 1
kwladyka 2020-06-24T08:50:32.090700Z

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

kwladyka 2020-06-24T08:51:37.091800Z

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

kwladyka 2020-06-25T09:42:21.097700Z

I don’t have ssh access

kwladyka 2020-06-25T09:52:39.097900Z

it works with ulimit for me

jumar 2020-06-25T11:33:03.098100Z

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.

kwladyka 2020-06-25T13:22:26.098300Z

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

kwladyka 2020-06-25T13:23:41.098500Z

> 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.

kwladyka 2020-06-25T13:24:25.098700Z

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

kwladyka 2020-06-25T13:25:25.098900Z

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

kwladyka 2020-06-25T13:26:41.099100Z

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

kwladyka 2020-06-25T13:27:12.099300Z

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

kwladyka 2020-06-25T13:27:22.099500Z

because in theory this shouldn’t happen

kwladyka 2020-06-25T13:27:36.099700Z

but for some reason it is happening in cloud run

kwladyka 2020-06-25T13:28:48.099900Z

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 :/

jumar 2020-06-25T20:16:03.100100Z

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)

kwladyka 2020-06-25T20:17:08.100400Z

yes, I was trying this on OS X

jumar 2020-06-25T20:22:15.100600Z

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

jumar 2020-06-25T20:22:40.100800Z

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

kwladyka 2020-06-25T20:28:37.101Z

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

kwladyka 2020-06-25T20:28:55.101300Z

Dockerfile has a answer about anvironment

kwladyka 2020-06-25T20:28:59.101500Z

I was trying also with v11

kwladyka 2020-06-25T20:29:11.101700Z

with buster and scratch

kwladyka 2020-06-25T20:29:49.101900Z

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

kwladyka 2020-06-25T20:34:07.102100Z

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

kwladyka 2020-06-25T20:34:40.102500Z

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

jumar 2020-06-25T20:37:48.102700Z

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

kwladyka 2020-06-25T20:38:56.102900Z

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

kwladyka 2020-06-25T20:39:39.103100Z

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

kwladyka 2020-06-25T20:40:01.103300Z

I mean the level of tired the topic

kwladyka 2020-06-25T20:40:43.103600Z

but it should work with app which is runnable

kwladyka 2020-06-25T20:43:31.103800Z

I will try in 10 minutes

kwladyka 2020-06-25T21:01:11.105800Z

https://pastebin.com/yp0PYtbG

kwladyka 2020-06-25T21:01:47.106200Z

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

kwladyka 2020-06-25T21:02:55.106400Z

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

kwladyka 2020-06-25T21:04:05.106600Z

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

kwladyka 2020-06-25T21:51:49.106800Z

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

jumar 2020-06-26T04:07:06.107Z

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

kwladyka 2020-06-26T08:11:15.107200Z

yes

jumar 2020-06-26T10:41:21.107400Z

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

👍 1
kwladyka 2020-06-26T10:51:23.107700Z

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.

jumar 2020-06-26T11:11:10.108Z

Could you run multiple processes in your docker container?

kwladyka 2020-06-26T11:13:17.108200Z

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

kwladyka 2020-06-26T11:13:25.108400Z

but for test purpose should be fine

kwladyka 2020-06-24T09:11:34.092400Z

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

kwladyka 2020-07-05T13:27:34.113800Z

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 ?

kwladyka 2020-07-05T13:28:13.114800Z

What is the best solution which you know?

jumar 2020-06-24T12:07:12.092900Z

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

jumar 2020-06-24T12:09:31.093200Z

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?

jumar 2020-06-24T12:31:51.093500Z

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

kwladyka 2020-06-24T13:21:37.095200Z

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

kwladyka 2020-06-24T13:25:02.095600Z

RSS?

jumar 2020-06-24T13:31:15.095800Z

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

kwladyka 2020-06-24T20:13:53.096Z

Do you mean 1/4 if RAM is default?

kwladyka 2020-06-24T20:14:42.096200Z

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