I started playing with quarkus and graalvm. I added files (txt and jpg) to resources in the project (src/main/resources/). To be sure that I have access to this file in controller I display size of it:
URL url = Thread.currentThread().getContextClassLoader().getResource("/Resource2.txt");
File file = new File(url.toURI());
return "Hello My Friend! File size in bytes = " + file.length();
and when I run it with maven (mvn quarkus:dev) it works. Controller code is here.
Problem occurred when I created native Quarkus application and try to run inside docker.
To be sure that file is included in native image, I added a big jpg file (3.3MB), created resources-config.json:
{ "resources":
{ "includes": [
{ "pattern": "IMG_3_3M\\.jpg$"},
{ "pattern": "Resources2\\.txt$"}
]
}}
and in application.properties added:
quarkus.native.additional-build-args = -H:ResourceConfigurationFiles=resources-config.json. The native runner size was increased from:
39M Mar 21 12:48 hello-quarkus-1.0-SNAPSHOT-runner
to: 44M Mar 21 12:19 hello-quarkus-1.0-SNAPSHOT-runner
So I assume that jpg file was included, but still when run native application inside docker image, I got NPE:
Caused by: java.lang.NullPointerException
at it.tostao.quickstart.GreetingResource.hello(GreetingResource.java:24)
where line 24: is url.toURI().
Any idea how I can read resources in native image? Is something missing in the configuration?
here is sample image to reproduce the problem, all commands needed to build and run native image you can find in README.MD:
https://github.com/sleski/hello-quarkus
So far I checked this urls and still was not able to find resources in native image:
• How to include classpath resources in a Quarkus native image?
• How to read classpath resources in Quarkus native image?
• https://quarkus.io/guides/writing-native-applications-tips
• Read txt file from resources folder on maven Quarkus project From Docker Container
First fix json
{
"resources": [
{
"pattern": "Resource2.txt"
}
]
}
or you can have *.txt as pattern. like in the doc
https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/Resources.md says use
InputStream resource = ModuleLayer.boot().findModule(moduleName).getResourceAsStream(resourcePath);
when I tried I had issues. you can see the working code below for your project
#Path("/hello")
public class GreetingResource {
#GET
#Produces(MediaType.TEXT_PLAIN)
public String hello() throws IOException {
String moduleName = "java.base";
String resourcePath = "/Resource2.txt";
Module resource = ModuleLayer.boot().findModule(moduleName).get();
InputStream ins = resource.getResourceAsStream(resourcePath);
if (ins == null) {
System.out.println("module came empty, now trying to load from GreetingResource");
ins = GreetingResource.class.getResourceAsStream(resourcePath);
}
if (ins != null) {
StringBuilder sb = new StringBuilder();
for (int ch; (ch = ins.read()) != -1; ) {
sb.append((char) ch);
}
return "Hello My Friend! File size in bytes = " + sb;
}
return "empty";
}
}
GreetingResource.class.getResourceAsStream(resourcePath); is actually bringing the resource here. I think this feature may change in the future so I left ModuleLayer in the code too. I used graalvm 17-21.3.0
you can find the build log below
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildRunner] C:\Program Files\GraalVM\graalvm-ce-java17-21.3.0\bin\native-image.cmd -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory -J-Dvertx.disableDnsResolver=true -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=3 -J-Duser.language=en -J-Duser.country=GB -J-Dfile.encoding=UTF-8 -H:-ParseOnce -J--add-exports=java.security.jgss/sun.security.krb5=ALL-UNNAMED -J--add-opens=java.base/java.text=ALL-UNNAMED -H:ResourceConfigurationFiles=resources-config.json -H:+PrintAnalysisCallTree -H:Log=registerResource:verbose -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy\$BySpaceAndTime -H:+JNI -H:+AllowFoldMethods -J-Djava.awt.headless=true -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:-AddAllCharsets -H:EnableURLProtocols=http -H:-UseServiceLoaderFeature -H:+StackTrace -J--add-exports=java.management/sun.management=ALL-UNNAMED hello-quarkus-1.0-SNAPSHOT-runner -jar hello-quarkus-1.0-SNAPSHOT-runner.jar
[hello-quarkus-1.0-SNAPSHOT-runner:20428] classlist: 2,920.35 ms, 0.94 GB
[hello-quarkus-1.0-SNAPSHOT-runner:20428] (cap): 1,493.84 ms, 0.94 GB
[hello-quarkus-1.0-SNAPSHOT-runner:20428] setup: 2,871.07 ms, 0.94 GB
[Use -Dgraal.LogFile=<path> to redirect Graal log output to a file.]
[thread:1] scope: main
[thread:1] scope: main.registerResource
ResourcesFeature: registerResource: Resource2.txt
14:23:38,709 INFO [org.jbo.threads] JBoss Threads version 3.4.2.Final
[thread:1] scope: main.registerResource
ResourcesFeature: registerResource: java/lang/uniName.dat
[hello-quarkus-1.0-SNAPSHOT-runner:20428] (clinit): 475.20 ms, 5.14 GB
[hello-quarkus-1.0-SNAPSHOT-runner:20428] (typeflow): 2,931.83 ms, 5.14 GB
[hello-quarkus-1.0-SNAPSHOT-runner:20428] (objects): 24,294.27 ms, 5.14 GB
[hello-quarkus-1.0-SNAPSHOT-runner:20428] (features): 2,979.07 ms, 5.14 GB
[hello-quarkus-1.0-SNAPSHOT-runner:20428] analysis: 32,083.24 ms, 5.14 GB
# Printing call tree to: C:\Users\ozkan\tmp\hello-quarkus\target\hello-quarkus-1.0-SNAPSHOT-native-image-source-jar\reports\call_tree_hello-quarkus-1.0-SNAPSHOT-runner_20220324_142406.txt
# Printing list of used methods to: C:\Users\ozkan\tmp\hello-quarkus\target\hello-quarkus-1.0-SNAPSHOT-native-image-source-jar\reports\used_methods_hello-quarkus-1.0-SNAPSHOT-runner_20220324_142407.txt
# Printing list of used classes to: C:\Users\ozkan\tmp\hello-quarkus\target\hello-quarkus-1.0-SNAPSHOT-native-image-source-jar\reports\used_classes_hello-quarkus-1.0-SNAPSHOT-runner_20220324_142407.txt
# Printing list of used packages to: C:\Users\ozkan\tmp\hello-quarkus\target\hello-quarkus-1.0-SNAPSHOT-native-image-source-jar\reports\used_packages_hello-quarkus-1.0-SNAPSHOT-runner_20220324_142407.txt
# Printing call tree for vm entry point to: C:\Users\ozkan\tmp\hello-quarkus\target\hello-quarkus-1.0-SNAPSHOT-native-image-source-jar\reports\csv_call_tree_vm_hello-quarkus-1.0-SNAPSHOT-runner_20220324_142408.csv
# Printing call tree for methods to: C:\Users\ozkan\tmp\hello-quarkus\target\hello-quarkus-1.0-SNAPSHOT-native-image-source-jar\reports\csv_call_tree_methods_hello-quarkus-1.0-SNAPSHOT-runner_20220324_142408.csv
# Printing call tree for virtual methods to: C:\Users\ozkan\tmp\hello-quarkus\target\hello-quarkus-1.0-SNAPSHOT-native-image-source-jar\reports\csv_call_tree_virtual_methods_hello-quarkus-1.0-SNAPSHOT-runner_20220324_142408.csv
# Printing call tree for entry points to: C:\Users\ozkan\tmp\hello-quarkus\target\hello-quarkus-1.0-SNAPSHOT-native-image-source-jar\reports\csv_call_tree_entry_points_hello-quarkus-1.0-SNAPSHOT-runner_20220324_142408.csv
# Printing call tree for direct edges to: C:\Users\ozkan\tmp\hello-quarkus\target\hello-quarkus-1.0-SNAPSHOT-native-image-source-jar\reports\csv_call_tree_direct_edges_hello-quarkus-1.0-SNAPSHOT-runner_20220324_142408.csv
# Printing call tree for overriden by edges to: C:\Users\ozkan\tmp\hello-quarkus\target\hello-quarkus-1.0-SNAPSHOT-native-image-source-jar\reports\csv_call_tree_override_by_edges_hello-quarkus-1.0-SNAPSHOT-runner_20220324_142408.csv
# Printing call tree for virtual edges to: C:\Users\ozkan\tmp\hello-quarkus\target\hello-quarkus-1.0-SNAPSHOT-native-image-source-jar\reports\csv_call_tree_virtual_edges_hello-quarkus-1.0-SNAPSHOT-runner_20220324_142408.csv
[hello-quarkus-1.0-SNAPSHOT-runner:20428] universe: 1,547.28 ms, 5.14 GB
[hello-quarkus-1.0-SNAPSHOT-runner:20428] (parse): 4,919.32 ms, 4.87 GB
[hello-quarkus-1.0-SNAPSHOT-runner:20428] (inline): 7,013.78 ms, 5.83 GB
[hello-quarkus-1.0-SNAPSHOT-runner:20428] (compile): 27,387.04 ms, 5.56 GB
[hello-quarkus-1.0-SNAPSHOT-runner:20428] compile: 41,595.59 ms, 5.56 GB
[hello-quarkus-1.0-SNAPSHOT-runner:20428] image: 2,515.22 ms, 5.56 GB
[hello-quarkus-1.0-SNAPSHOT-runner:20428] write: 858.79 ms, 5.56 GB
[hello-quarkus-1.0-SNAPSHOT-runner:20428] [total]: 90,068.97 ms, 5.56 GB
# Printing build artifacts to: C:\Users\ozkan\tmp\hello-quarkus\target\hello-quarkus-1.0-SNAPSHOT-native-image-source-jar\hello-quarkus-1.0-SNAPSHOT-runner.build_artifacts.txt
[INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 94323ms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:37 min
[INFO] Finished at: 2022-03-24T14:24:56Z
[INFO] ------------------------------------------------------------------------
This is how I solved the problem - example with changes are in this branch: https://github.com/sleski/hello-quarkus/tree/solution_for_native
Explanations:
Image is in: src/main/resources/images and name is:IMG_3_3M.jpg.
In application.properties I added images.location variable:
images.location=src/main/resources/images/
%prod.images.location=/work/images/
and in the java controller I added:
#ConfigProperty(name = "images.location")
String imageLocation;
in docker.native added: COPY target/classes/images/*.jpg /work/images/
When I start application with querkus:dev it is getting image from src/main/resources/images and when I run narive image: /work/images.
In both cases work: File size is = 3412177.
Related
I have written a very simple app in Flutter, for both iOS, Android and the web.
Lately, I realized that if I browse the "storage" settings page on my iPhone, my prod app, as it is distributed on the App Store, weighs about 500 MB. Most of it comes from the "documents and data" part, the app itself isn't huge:
Storage page
This is unexpected as the only thing I am storing on purpose is a small sqlite database, which in my case is about 30 KB.
Following this guide from the Apple support page, I was able to download my app's container, which is indeed about 500 MB. It turns out most of the weight comes from inside of a tmp folder, as shown by the output of du -sh AppData/tmp/*:
0B AppData/tmp/count0fSKCX
0B AppData/tmp/count1N2yFY
32K AppData/tmp/count1tKqnr
0B AppData/tmp/count2BxlSk
24K AppData/tmp/count2VKOVX
0B AppData/tmp/count2tnzwn
[...]
0B AppData/tmp/count8kl1hK
53M AppData/tmp/count8kqOke
0B AppData/tmp/count8ssdC7
[...]
0B AppData/tmp/countZHwkA9
26M AppData/tmp/countZHx1v8
53M AppData/tmp/countZKP9JU
0B AppData/tmp/counta5fYmx
[...]
If I take a look at what's inside of one of those huge 50+ MB folders, here is what takes so much space:
du -sh AppData/tmp/countZKP9JU/count/*
26M AppData/tmp/countZKP9JU/count/main.dart.dill
20K AppData/tmp/countZKP9JU/count/main.dart.incremental.dill
26M AppData/tmp/countZKP9JU/count/main.dart.swap.dill
I failed to find useful documentation about those files, as I am not sure what to look for: is the problem in my Dart config, in my Flutter config, in my App config, ...? Can you guys please enlighten me?
Edit: Here is some version info that might be useful
Flutter 2.5.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision ffb2ecea52 (5 weeks ago) • 2021-09-17 15:26:33 -0400
Engine • revision b3af521a05
Tools • Dart 2.14.2
iOS version: 15.0.2
In case someone runs into the same issue, I ended up writing my own cleanup logic on startup, calling getApplicationDocumentsDirectory().parent.list() and then deleting the tmp child folder if it exists.
I don't know if this is necessary at all in the end, as this tmp folder growing infinitely might only happen because of the development builds I keep installing on my phone. But this cleanup step probably won't hurt anyway.
Edit: Here is the code. Feel free to improve it, I think it probably logs an exception on other platforms (but it doesn't crash):
import 'package:path_provider/path_provider.dart';
[...]
#override
void initState() {
_cleanUpTemporaryDirectory();
super.initState();
}
[...]
_cleanUpTemporaryDirectory() async {
final documentsDirectory = await getApplicationDocumentsDirectory();
documentsDirectory.parent.list().forEach((child) async {
if (child is Directory && child.path.endsWith('/tmp')) {
print('Deleting temp folder at ${child.path}...');
try {
await child.delete(recursive: true);
print('Temp folder was deleted with success');
} catch (error) {
print('Temp folder could not be deleted: $error');
}
}
});
}
I am trying to use Cache Task in Azure Pipelines for the Docker setup. According to the documentation I need to set below parameters:
Key (Required)
Path (Required)
RestoreKeys (Optional)
- task: Cache#2
inputs:
key: 'docker | "$(Agent.OS)" | cache'
path: '$(Pipeline.Workspace)/docker'
Unfortunately, the post-job for Cache task always failing with this error. Any suggestions?
Starting: Cache
==============================================================================
Task : Cache
Description : Cache files between runs
Version : 2.0.1
Author : Microsoft Corporation
Help : https://aka.ms/pipeline-caching-docs
==============================================================================
Resolving key:
- docker [string]
- "Windows_NT" [string]
- cache [string]
Resolved to: docker|"Windows_NT"|cache
ApplicationInsightsTelemetrySender will correlate events with X-TFS-Session xxxx
Getting a pipeline cache artifact with one of the following fingerprints:
Fingerprint: `docker|"Windows_NT"|cache`
There is a cache miss.
tar: could not chdir to 'D:\a\1\docker'
ApplicationInsightsTelemetrySender correlated 1 events with X-TFS-Session xxxx
##[error]Process returned non-zero exit code: 1
Finishing: Cache
Update: After making the changes in creating the direction based on the suggested answer the cache has been hit but the size of it is 0.0MB. Do we need to take care of copy ourselves?
Starting: Cache
==============================================================================
Task : Cache
Description : Cache files between runs
Version : 2.0.1
Author : Microsoft Corporation
Help : https://aka.ms/pipeline-caching-docs
==============================================================================
Resolving key:
- docker [string]
- "Windows_NT" [string]
- cache [string]
Resolved to: docker|"Windows_NT"|cache
ApplicationInsightsTelemetrySender will correlate events with X-TFS-Session xxxxxx
Getting a pipeline cache artifact with one of the following fingerprints:
Fingerprint: `docker|"Windows_NT"|cache`
There is a cache hit: `docker|"Windows_NT"|cache`
Used scope: 3;xxxx;refs/heads/master;xxxx
Entry found at fingerprint: `docker|"Windows_NT"|cache`
7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21
Extracting archive:
Expected size to be downloaded: 0.0 MB
**Downloaded 0.0 MB out of 0.0 MB (214%).
Downloaded 0.0 MB out of 0.0 MB (214%).**
Download statistics:
Total Content: 0.0 MB
Physical Content Downloaded: 0.0 MB
Compression Saved: 0.0 MB
Local Caching Saved: 0.0 MB
Chunks Downloaded: 3
Nodes Downloaded: 0
--
Path =
Type = tar
Code Page = UTF-8
Everything is Ok
I could reproduce the same issue when the docker folder is not created before the cache task.
You need to create the folder before the cache task or directly use the existing folder.
Here is an example:
pool:
vmImage: windows-latest
steps:
- task: PowerShell#2
inputs:
targetType: 'inline'
script: 'New-Item -ItemType directory -Path $(Pipeline.Workspace)/docker'
- task: Cache#2
inputs:
key: 'docker | "$(Agent.OS)" | cache'
path: '$(Pipeline.Workspace)/docker'
I got the same issue. After creating the cache path folder before cache task, error is resolved.
- task: PowerShell#2
inputs:
targetType: 'inline'
script: 'New-Item -ItemType directory -Path $(Pipeline.Workspace)/docker'
As mentioned, still the cache itself didn't work as expected. I modified the cache folder, cache key and cache path to different values, since cache is immutable. And Cache key and restoreKeys are set to same value.
pool:
vmImage: windows-2019
variables:
MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/testcache1/.m2/repository
MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
steps:
- task: PowerShell#2
inputs:
targetType: 'inline'
script: 'New-Item -ItemType directory -Path $(MAVEN_CACHE_FOLDER)'
- task: Cache#2
inputs:
key: mykeyazureunique
restoreKeys: mykeyazureunique
path: $(MAVEN_CACHE_FOLDER)
displayName: Cache Maven local repo
- task: MavenAuthenticate#0
displayName: Authenticate Maven to Artifacts feed
inputs:
artifactsFeeds: artifacts-maven
#mavenServiceConnections: serviceConnection1, serviceConnection2 # Optional
- task: Maven#3
displayName: Maven deploy into Artifact feed
inputs:
mavenPomFile: 'pom.xml'
goals: 'clean install'
mavenOptions: '-Xmx3072m $(MAVEN_OPTS)'
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: false
Note: Cache will be set only if the job is successful.
If the cache is saved successfully, then you will see below message in the Post-job:Cache
Content upload statistics:
Total Content: 41.3 MB
Physical Content Uploaded: 17.9 MB
Logical Content Uploaded: 20.7 MB
Compression Saved: 2.8 MB
Deduplication Saved: 20.7 MB
Number of Chunks Uploaded: 265
Total Number of Chunks: 793
Now the cache is set properly, we have to make sure Cache location is picked up while execution. First thing, verify that cache is restored properly. Below log will be displayed if restore is done
There is a cache hit: `mykeyazureunique`
Extracting archive:
Expected size to be downloaded: 20.7 MB
Downloaded 0.0 MB out of 20.7 MB (0%).
Downloaded 20.7 MB out of 20.7 MB (100%).
Downloaded 20.7 MB out of 20.7 MB (100%).
Then Cache location has to be communicated to target runner. In my case, I have used Maven. So I have set cache location in the Maven_opts.
MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
mavenOptions: '-Xmx3072m $(MAVEN_OPTS)'
When running bazel test the output contains only summary of the all tests, including total run time.
Running bazel with performance profiling does not help, because it does not indicate each test time.
So how to get the info about each test execution time?
UPD:
I have a sample repo to reproduce my problem:
$ git clone https://github.com/MikhailTymchukFT/bazel-java
$ cd bazel-java
$ bazel test //:AllTests --test_output=all --test_summary=detailed
Starting local Bazel server and connecting to it...
INFO: Analyzed 2 targets (20 packages loaded, 486 targets configured).
INFO: Found 2 test targets...
INFO: From Testing //:GreetingTest:
==================== Test output for //:GreetingTest:
JUnit4 Test Runner
..
Time: 0.017
OK (2 tests)
BazelTestRunner exiting with a return value of 0
JVM shutdown hooks (if any) will run now.
The JVM will exit once they complete.
-- JVM shutdown starting at 2020-04-07 09:44:56 --
================================================================================
INFO: From Testing //:MainTest:
==================== Test output for //:MainTest:
JUnit4 Test Runner
.
Time: 0.016
OK (1 test)
BazelTestRunner exiting with a return value of 0
JVM shutdown hooks (if any) will run now.
The JVM will exit once they complete.
-- JVM shutdown starting at 2020-04-07 09:44:57 --
================================================================================
INFO: Elapsed time: 21.009s, Critical Path: 6.68s
INFO: 10 processes: 6 darwin-sandbox, 4 worker.
INFO: Build completed successfully, 18 total actions
Test cases: finished with 3 passing and 0 failing out of 3 test cases
INFO: Build completed successfully, 18 total actions
I can see execution time of both tests in GreetingTest
==================== Test output for //:GreetingTest:
JUnit4 Test Runner
..
Time: 0.017
OK (2 tests)
, but cannot see the execution time of each test in this class/rule.
With --test_summary=short (the default value), the end of the output looks like this (lines for the other 325 tests truncated):
INFO: Elapsed time: 148.326s, Critical Path: 85.71s, Remote (0.00% of the time): [queue: 0.00%, setup: 0.00%, process: 0.00%]
INFO: 680 processes: 666 linux-sandbox, 14 worker.
INFO: Build completed successfully, 724 total actions
//third_party/GSL/tests:no_exception_throw_test (cached) PASSED in 0.4s
//third_party/GSL/tests:notnull_test (cached) PASSED in 0.5s
//aos/events:shm_event_loop_test PASSED in 12.3s
Stats over 5 runs: max = 12.3s, min = 2.4s, avg = 6.3s, dev = 3.7s
//y2018/control_loops/superstructure:superstructure_lib_test PASSED in 2.3s
Stats over 5 runs: max = 2.3s, min = 1.3s, avg = 1.8s, dev = 0.4s
Executed 38 out of 329 tests: 329 tests pass.
INFO: Build completed successfully, 724 total actions
Confusingly, --test_summary=detailed doesn't include the times, even though the name sounds like it should have strictly more information.
For sharded tests, that output doesn't quite have every single test execution, but it does give statistics about them as shown above.
If you want to access the durations programmatically, the build event protocol has a TestResult.test_attempt_duration_millis field.
Alternatively, using --test_output=all will print all the output from your actual test binaries, including the ones that pass. Many testing frameworks print a total execution time there.
There is a testlogs folder where you can find .xml files with the execution times of each testcase.
The bazel-testlogs symlink points to the same location.
For my example, these files will be located at /private/var/tmp/_bazel_<user>/<some md5 hash>/execroot/<project name>/bazel-out/<kernelname>-fastbuild/testlogs/GreetingTest/test.xml
The content of that file is like this:
<?xml version='1.0' encoding='UTF-8'?>
<testsuites>
<testsuite name='com.company.core.GreetingTest' timestamp='2020-04-07T09:58:28.409Z' hostname='localhost' tests='2' failures='0' errors='0' time='0.01' package='' id='0'>
<properties />
<testcase name='sayHiIsString' classname='com.company.core.GreetingTest' time='0.01' />
<testcase name='sayHi' classname='com.company.core.GreetingTest' time='0.0' />
<system-out />
<system-err /></testsuite></testsuites>
I am using task-launcher-sink 1.3.1.RELEASE Version and SDCF Version 1.4.0.RELEASE to launch my task at PCF. The default allocated heap for the my task is not sufficient to run it, as my task is processing data of larger size. So, it is giving the heap allocation error , Resource exhaustion event: the JVM was unable to allocate memory from the heap.
I am able to run my task by providing JAVA_OPTS=-Xms128m -Xmx512m in MyTask>Setting>User Provided Environment Variables manually on PCF.
But as I am using task-launcher-sink, this parameter to provided as environment variable or deployment parameter.
Below are the Logs I am getting:
2019-04-26T11:32:35.522+05:30 [APP/TASK/MyTask/0] [OUT] Memory usage:
2019-04-26T11:32:35.523+05:30 [APP/TASK/MyTask/0] [OUT] Heap memory: init 16777216, used 108648024, committed 344653824, max 344653824
2019-04-26T11:32:35.524+05:30 [APP/TASK/MyTask/0] [OUT] Hint: Heap memory is over 95% full. To increase it, increase the container size.
2019-04-26T11:32:35.526+05:30 [APP/TASK/MyTask/0] [OUT] Non-heap memory: init 2555904, used 103426448, committed 105512960, max 631562240
2019-04-26T11:32:35.527+05:30 [APP/TASK/MyTask/0] [OUT] Memory pool usage:
2019-04-26T11:32:35.528+05:30 [APP/TASK/MyTask/0] [OUT] Code Cache: init 2555904, used 18623104, committed 18743296, max 251658240
2019-04-26T11:32:35.529+05:30 [APP/TASK/MyTask/0] [OUT] Metaspace: init 0, used 75305304, committed 76939264, max 194146304
2019-04-26T11:32:35.530+05:30 [APP/TASK/MyTask/0] [OUT] Compressed Class Space: init 0, used 9498136, committed 9830400, max 185757696
2019-04-26T11:32:35.531+05:30 [APP/TASK/MyTask/0] [OUT] Eden Space: init 4521984, used 3132632, committed 95092736, max 95092736
2019-04-26T11:32:35.533+05:30 [APP/TASK/MyTask/0] [OUT] Survivor Space: init 524288, used 0, committed 11862016, max 11862016
2019-04-26T11:32:35.534+05:30 [APP/TASK/MyTask/0] [OUT] Tenured Gen: init 11206656, used 105515392, committed 237699072, max 237699072
2019-04-26T11:32:35.534+05:30 [APP/TASK/MyTask/0] [ERR] jvmkill killing current process
2019-04-26T11:32:35.534+05:30 [APP/TASK/MyTask/0] [OUT] 2019-04-26 06:02:35
You have to pass the -Xms128m -Xmx512m options as a deployment property of the TaskLaunchRequest:
deployer.{app}.cloudfoundry.javaOpts=-Xms128m -Xmx512m
where {app} stands for the name of your SCDF Task app, i.e. the identifier referenced in the definition of your task create SCDF shell command (not to be confused with the PCF app name).
In addition, if necessary, you should be able to control the total amount of memory made available to the PCF app (as far as the quota allows) by adding another deployment property:
deployer.{app}.cloudfoundry.memory=1g
Note that I found this out by studying and debugging the task launcher code. The documentation could be a little clearer in this regard.
We are having an issue on our production Elasticsearch cluster where Elasticsearch seems to be consuming, over time, all of the RAM on each server. Each box has 128GB of RAM so we run two instances, 30GB is allocated to each for the JVM Heap. The remaing 68G is left for the OS and Lucene. We rebooted each of the servers last week and the RAM was started off just right using 24% of the RAM for each Elasticsearch process. It's now been almost a week and our memory consumption has gone up to around 40% per Elasticsearch instance. I have attached our config file in hopes that someone may be able to help figure out why Elasticsearch is growing out past the limit we have set for memory utilization.
Currently we are running ES 1.3.2 but will be upgrading to 1.4.2 next week with our next release.
Here is a view of top (extra fields removed for clarity) from right after the reboot:
PID USER %MEM TIME+
2178 elastics 24.1 1:03.49
2197 elastics 24.3 1:07.32
and one today:
PID USER %MEM TIME+
2178 elastics 40.5 2927:50
2197 elastics 40.1 3000:44
elasticserach-0.yml:
cluster.name: PROD
node.name: "PROD6-0"
node.master: true
node.data: true
node.rack: PROD6
cluster.routing.allocation.awareness.force.rack.values:
PROD4,PROD5,PROD6,PROD7,PROD8,PROD9,PROD10,PROD11,PROD12
cluster.routing.allocation.awareness.attributes: rack
node.max_local_storage_nodes: 2
path.data: /es_data1
path.logs:/var/log/elasticsearch
bootstrap.mlockall: true
transport.tcp.port:9300
http.port: 9200
http.max_content_length: 400mb
gateway.recover_after_nodes: 17
gateway.recover_after_time: 1m
gateway.expected_nodes: 18
cluster.routing.allocation.node_concurrent_recoveries: 20
indices.recovery.max_bytes_per_sec: 200mb
discovery.zen.minimum_master_nodes: 10
discovery.zen.ping.timeout: 3s
discovery.zen.ping.multicast.enabled: false
discovery.zen.ping.unicast.hosts: XXX
index.search.slowlog.threshold.query.warn: 10s
index.search.slowlog.threshold.query.info: 5s
index.search.slowlog.threshold.query.debug: 2s
index.search.slowlog.threshold.fetch.warn: 1s
index.search.slowlog.threshold.fetch.info: 800ms
index.search.slowlog.threshold.fetch.debug: 500ms
index.indexing.slowlog.threshold.index.warn: 10s
index.indexing.slowlog.threshold.index.info: 5s
index.indexing.slowlog.threshold.index.debug: 2s
monitor.jvm.gc.young.warn: 1000ms
monitor.jvm.gc.young.info: 700ms
monitor.jvm.gc.young.debug: 400ms
monitor.jvm.gc.old.warn: 10s
monitor.jvm.gc.old.info: 5s
monitor.jvm.gc.old.debug: 2s
action.auto_create_index: .marvel-*
action.disable_delete_all_indices: true
indices.cache.filter.size: 10%
index.refresh_interval: -1
threadpool.search.type: fixed
threadpool.search.size: 48
threadpool.search.queue_size: 10000000
cluster.routing.allocation.cluster_concurrent_rebalance: 6
indices.store.throttle.type: none
index.reclaim_deletes_weight: 4.0
index.merge.policy.max_merge_at_once: 5
index.merge.policy.segments_per_tier: 5
marvel.agent.exporter.es.hosts: ["1.1.1.1:9200","1.1.1.1:9200"]
marvel.agent.enabled: true
marvel.agent.interval: 30s
script.disable_dynamic: false
and here is /etc/sysconfig/elasticsearch-0 :
# Directory where the Elasticsearch binary distribution resides
ES_HOME=/usr/share/elasticsearch
# Heap Size (defaults to 256m min, 1g max)
ES_HEAP_SIZE=30g
# Heap new generation
#ES_HEAP_NEWSIZE=
# max direct memory
#ES_DIRECT_SIZE=
# Additional Java OPTS
#ES_JAVA_OPTS=
# Maximum number of open files
MAX_OPEN_FILES=65535
# Maximum amount of locked memory
MAX_LOCKED_MEMORY=unlimited
# Maximum number of VMA (Virtual Memory Areas) a process can own
MAX_MAP_COUNT=262144
# Elasticsearch log directory
LOG_DIR=/var/log/elasticsearch
# Elasticsearch data directory
DATA_DIR=/es_data1
# Elasticsearch work directory
WORK_DIR=/tmp/elasticsearch
# Elasticsearch conf directory
CONF_DIR=/etc/elasticsearch
# Elasticsearch configuration file (elasticsearch.yml)
CONF_FILE=/etc/elasticsearch/elasticsearch-0.yml
# User to run as, change this to a specific elasticsearch user if possible
# Also make sure, this user can write into the log directories in case you change them
# This setting only works for the init script, but has to be configured separately for systemd startup
ES_USER=elasticsearch
# Configure restart on package upgrade (true, every other setting will lead to not restarting)
#RESTART_ON_UPGRADE=true
Please let me know if there is any other data I can provide. Thanks in advance for any help.
total used free shared buffers cached
Mem: 129022 119372 9650 0 219 46819
-/+ buffers/cache: 72333 56689
Swap: 28603 0 28603
What you are seeing isn't heap blow out, heap will always be restricted by what you set in the config. free -m and top report on OS related use, so the use there would most likely be the OS caching FS calls.
This will not cause a java OOM.
If you are experiencing java OOM, which is directly related to the java heap running out of space, then there is something else at play. Your logs may provide some info around that.