High CPU usage when shifting from Java 8 to Java 11 with G1GC
We are having following VM settings for our server. This configuration works perfectly when running Java 8. But when we switch JVM to Java 11 OpenJDK, the server stop responding due to CPU usage collapse. Is there anything we need to setup regarding Java11 G1 args that is essential on Java 11 environment?
-Xloggc:logs/gc.log
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-XX:+PrintHeapAtGC
-XX:+PrintTenuringDistribution
-XX:PrintFLSStatistics=1
-XX:+PrintGCApplicationStoppedTime
-XX:+PrintReferenceGC
# G1 GC
-XX:+UseG1GC
-XX:+DisableExplicitGC
-XX:+ParallelRefProcEnabled
# Shenandoah GC
#-XX:+UseShenandoahGC
-Xmx22g
-Xms22g
-Xss256k
-XX:-OmitStackTraceInFastThrow
-XX:-LoopUnswitching
-XX:+PrintFlagsFinal
do you know?
how many words do you know
See also questions close to this topic
-
Read each name in Array list to create seperate object for
I have a file that has student names, age, and an id number. I have a student class that holds the everything above for each student object. I stored all the names, id numbers. and age separately in an array list. Now im trying to assign the info to create a student object.
public class Student { private String lName; private int idNumber; private int age; public Student() { lName = ""; idNumber = 0; age = 0; } public Student(String l, int i, int a) { lName = l; idNumber = i; age = a; } public void setName(String last) { lName = last; } public String getName() { return lName; } public void setIdNum(int num) { idNumber = num; } public int getIdNum() { return idNumber; } public void setAge(int a) { age = a; } public int getAge() { return age; } }
My Text File looks something like this: This info is stored in parallel array lists. I don't quite get how to implement this into an object to pass it into my second contractor method.
Josh 2134 19 Smith 5256 21 Rogers 9248 19 Andrew 7742 20
Here's what I've tried;
public static void main(String[] args) { String file = "studentData.txt"; Scanner reader = new Scanner(file); ArrayList<String> lastNames = lNames(file); ArrayList<Integer> idNumbers = idNum(file); ArrayList<Integer> ageList = ages(file); Scanner input = new Scanner(System.in); Student s1 = new Student(); // confused about how to implement this constructor with the textile info for (int i = 0; i<idNumbers.size(); i++) { Student user = new Student(lastNames.get(i), idNumbers.get(i), ageList.get(i)); } //user enters idNumber to display age System.out.println("Enter ID Number"); //exception handling to be added int idNum = input.nextInt(); for (int i = 0; i<idNumbers.size(); i++) { if (idNum == idNumbers.get(i)) { s1.setAge(ageList.get(i)); System.out.println(s1.getAge()); } } }
-
Using EdittextPreference for Goto search
sorry for my poor English. I want to use EditTextPreference in my bottom nav like the pic below, ![screenshot][1]
I have recycleview xml in my project with in many sub cardview layouts(which is scrollable) and I want to create item in the bottom nav which is called "Goto". When the "Goto" item is clicked i want it to pop-up like the screenshot. And when user enters a number(according to the cardviews i.e if the number of cardview is 40 user must enter 1-40) I want to search the cardview by its ID. Thank you and I hope u got it, If u have any questions let me know [1]: https://i.stack.imgur.com/grK8P.jpg
My xml format look like this. As you see in the blow since the cardviews are huge in number it is not cool to scroll all the way down that is why i need Goto item in the bottom nav to search it by its ID when the user click number in the EditTextPreference as u see in the screenshot. i.e The screenshot is not from my app
<LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> .. .. .. .. many more..
-
How to get remaining time of the day in java?
I would like to calculate the time remaining for next day 00:00:00 from the current date time.
For e.g. time difference between 2
022-05-07T05:49:41.883807900Z
and2022-05-08T00:00:00Z
Expected answer:
18:10:19
or 65419 (in seconds).How can I achieve this with efficiently using java 8?
-
efficient lookup where key is a set of key-value pairs pointing to an object
I seek for some inspirations. my problem is how to pool an object identified by key-value pairs. I am working on JVM and don't want to create garbage when creating those objects in runtime - that's why an idea of pooling.
so lets give some example - user can provide identifiers like
(A(1) B(4))
,(A(1) B(2) C('foo') E(0))
,(B(4) A(1))
,(A(0))
, etc.. - for each of those set of pairs I would like to get unique reference to object created earlier. mind that(A(1) B(4))
and(B(4) A(1))
should point to exactly the same ref - of course I can sort by keys and then perform calculation.of course I could create a map in runtime as a key and keep a
Map<Map<K,V>, T>
but this is not really efficient when we talk about X thousands of lookup per second.I was thinking about hashing those input pairs to get unique id - but somehow I have to prove that hashing function will have no collisions when number or variety of k-v increase in runtime. I expect to have no more than 1M of unique k-v pairs, so computing an id would be the best solution and map that id to an object - but I need function that will calculate such id.
maybe some smart graph structure could be a solution, the only trouble I have is that not only keys create a graph but also values of those keys.
any help would be appreciated.
-
Chronicle-Queue: Why does busy-waiting tailer generate garbage when spinning (nothing to be read)?
I have a busy-waiting loop in which a tailer is constantly trying to read from a queue:
final Bytes<ByteBuffer> bbb = Bytes.elasticByteBuffer(MAX_SIZE, MAX_SIZE); // Busy wait loop. while (true) { tailer.readDocument(wire -> { wire.read().marshallable(m -> { m.read(DATA).bytes(bbb, true); long rcvAt = m.read(RCVAT).int64(); System.out.println(rcvAt); }); }); }
Why does this code generate garbage even when there is nothing to read from the queue?
Relevant JVM flags:
-server -XX:InitialHeapSize=64m -XX:MaxHeapSize=64m
GC logs and memory profile:
GC logs is flooded with logs like this:
... [30.071s][info][gc ] GC(1755) Pause Young (Normal) (G1 Evacuation Pause) 23M->6M(30M) 0.250ms [30.084s][info][gc ] GC(1756) Pause Young (Normal) (G1 Evacuation Pause) 23M->7M(30M) 0.386ms [30.096s][info][gc ] GC(1757) Pause Young (Normal) (G1 Evacuation Pause) 24M->7M(30M) 0.544ms [30.109s][info][gc ] GC(1758) Pause Young (Normal) (G1 Evacuation Pause) 24M->7M(30M) 0.759ms [30.122s][info][gc ] GC(1759) Pause Young (Normal) (G1 Evacuation Pause) 24M->7M(30M) 0.808ms [30.135s][info][gc ] GC(1760) Pause Young (Normal) (G1 Evacuation Pause) 24M->7M(30M) 0.937ms ...
-
tensorflow models load successfully individually, but not sequentially? Garbage collection?
Sorry about the vague title but I'm not sure exactly how to describe it.
I am currently running tests on a model written in tensorflow.compat.v1. When it is used for inference, it must be restored as follows:
class Model def __init__(self, filepath): ... self.sess, self.saver = self.setup_tf() self.merge = tf.compat.v1.summary.merge(tf.compat.v1.summary.scalar('loss', self.loss)]) def setup_tf(): sess = tf.compat.v1.Session() # TF session saver = tf.compat.v1.train.Saver(max_to_keep=1) latest_snapshot = tf.train.latest_checkpoint(join("../", self.model_dir)) saver.restore(sess, latest_snapshot) return sess, saver
I have 2 of these tests, involving restoring a model and performing some inferences with it. After successful loading and inference of the first model, the second test fails to restore the model completely. The specific error here is
tensorflow.python.framework.errors_impl.NotFoundError: Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:
class TestInference(unittest.TestCase): def setUp(self): pass def tearDown(self): pass: def test1: model = Model(filepath) model.infer() def test2: model = Model(filepath) model.infer()
However when I run each test individually (commenting one out), there is no problem in restoring the model. Even when I swap the order of the models being loaded around, there the first one is always successful and the second one fails.
I figure that I should be using setUp and tearDown for each test, but I'm confused on what exactly I should be 'tearing down'? Is it garbage collection? I have tried gc.collect, but the same error occurs.
Here is the testing class, if it helps:
-
Why HashMap put so much faster after jdk8?
Why does this class, built with Java 8, run 7.5x faster on Java 11 than Java 8?
import java.time.Duration; import java.time.LocalDateTime; import java.util.HashMap; public class JMapSpeed { public static void main(String[] args) { HashMap<Integer, Integer> map = new HashMap<>(10_000_000); LocalDateTime start=LocalDateTime.now(); for (int n=0; n< 10_000_000; n++) { map.put(n,n); } LocalDateTime stop= LocalDateTime.now(); System.out.println("Duration: " + Duration.between(start, stop).toMillis()); System.out.println("Iterations: " + map.size()); } }
-
Java classpath problem of dependency's versions conflict
I'd like to know if it's possible to solve a case where I have a dependency
org.bla:artifact-a:x.y.z
with is dependent onorg.bla:dep-c:1.0.0
, and uses its classBla()
. Assume I have another dependencyorg.bla:artifact-b:x.y.z
, that is dependent onorg.bla:dep-c:2.0.0
, and uses its classNewBla()
with was not exist in version1.0.0
.The dependency graph would look like this:
+--- org.bla:artifact-a:x.y.z | +--- org.bla:dep-c:1.0.0 +--- org.bla:artifact-b:x.y.z | +--- org.bla:dep-c:2.0.0
This situation raises the need for having both
org.bla:dep-c:1.0.0
andorg.bla:dep-c:2.0.0
on the classpath, otherwise it won't be possible to useartifact-a
withartifact-b
. On other languages e.g. node.js, the package manager will be able to bring both dependencies and by putting them in their own hierarchy, it'll allow resolving both of them and making sure each will use only it's own dependency's version.After questions like this some will probably suggest creating another project which will import one of the dependencies and will shadow it so the hierarchy will look like this:
+--- org.bla:artifact-a:x.y.z | +--- shadow.org.bla:dep-c:1.0.0 +--- org.bla:artifact-b:x.y.z | +--- org.bla:dep-c:2.0.0
This hard-coded solution will indeed work, but it won't scale well.
-
Does implementing Serializable interface gives any features to the class implementing it?
What is the use of implementing Serializable interface? It is said that Serializable is a marker interface. A marker interface provides run-time information to JVM. What wonders me what is happening in the runtime? How OutputObjectStream is able to serialize an object which implements Serializable?
-
Order ArrayList with Int and String in Kotlin
I have the given array
val things = arrayOf<Any>("Jack", 8, 2, 6, "King", 5, 3, "Queen", "Jack");
Below is the code I have used
things.set(things.indexOf("Jack"), 11); things.set(things.indexOf("Queen"), 12); things.set(things.indexOf("King"), 13); things.sort(); things.set(things.indexOf(11), "Jack")); things.set(things.indexOf(12), "Queen"); things.set(things.indexOf(13), "King"); things.joinToString(":"); things.forEach { System.out.print(it) }
Here is the error I keep getting
Unexpected tokens (use ';' to separate expressions on the same line) Expecting an element
After removing the trailing bracket, I now get the following error
Exception in thread "main" java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String (java.lang.Integer and java.lang.String are in module java.base of loader 'bootstrap') at java.lang.String.compareTo (:-1) at java.util.ComparableTimSort.binarySort (:-1) at java.util.ComparableTimSort.sort (:-1)
-
Setting VM argument via pom.xml
I need to set
-Duser.language
viapom.xml
since I need language specific database queries. When I pass-Duser.language=tr
to VM options upon running spring boot application on Intellij, it works. But I need this to be done inpom.xml
for profiling.Below ways are not working. Language is not set.
<profile> <properties> <argLine>-Duser.language=tr -Duser.region=TR</argLine> </properties> ... </profile>
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> <verbose>true</verbose> <fork>true</fork> <compilerArgs> <arg>-J-Duser.language=tr_TR</arg> </compilerArgs> </configuration> </plugin>
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> <configuration> <argLine>-Duser.language=tr -Duser.region=TR</argLine> <systemPropertyVariables> <user.language>tr</user.language> <user.region>TR</user.region> </systemPropertyVariables> </configuration> </plugin>
Only this is working but I need to run application with
mvn spring-boot:run
for this to work and that is not an option.<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <jvmArguments> -Duser.language=tr </jvmArguments> </configuration> ... </plugin>
How can I pass vm arguments via pom.xml?