Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Runtime.getRuntime().availableProcessors() is always returning 1 on Container-Optimized OS

I'm deploying elasticsearch on kubernetes engine on GCP and running into aperformance issue. Elasticsearch determines the size of various thread pools based on the number of cores. Even though I have an 32 core VM created, the thread pool size is just 1.

I did write a test program to print the Runtime.getRuntime().availableProcessors() and it just prints as 1.

I guess it has something to do with the "Container-Optimized OS" which is the only OS allowed on the VMs using Kubernetes Engine. When i create an Debian VM on GCP the Runtime.getRuntime().availableProcessors() returns 8. Not sure how is elasticsearch is being used on the GCPs kubernetes engine. Any ideas or suggestions are welcome.

When i create an Debian VM on GCP without kubernetes, the Runtime.getRuntime().availableProcessors() returns 8.

like image 852
Shankar Shantharaju Avatar asked May 24 '26 18:05

Shankar Shantharaju


1 Answers

you can try

-XX:ActiveProcessorCount=[host_cpu_count]

and then

Runtime.getRuntime().availableProcessors()

will return

host_cpu_count

like image 76
Ranger Avatar answered May 26 '26 07:05

Ranger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!