JVM Geheugen metrics monitoren

De JVM bevat meerdere geheugen onderdelen die met bijvoorbeeld micrometer op te halen zijn.

Heap geheugen old generation:

heap_old_gen: Tenured Space: The objects which reach to max tenured threshold during the minor GC or young GC, will be moved to “Tenured Space” or “Old Generation Space“.

Heap geheugen young generation:

heap_survivor_space : This contains the objects that have survived from the Young garbage collection or Minor garbage collection. We have two equally divided survivor spaces called S0 and S1.

max_heap_eden_space: When we create an object, the memory will be allocated from the Eden Space.

Non-heap geheugen:

nonheap_metaspaces : Hierin staat de class metadata als compressed class space disabled is (die staat voor 64bit machines standaard aan, en is aan te passen met UseCompressedClassPointers).

nonheap_compressed_class_space: Hierin staan de classes metadata als de compressed class space enabled is (default staat hij aan), de size is aan te passen met -XX:CompressedClassSpaceSize.

nonheap_non_nmethods: A non-method code heap containing non-method code, such as compiler buffers and bytecode interpreter. This code type will stay in the code cache forever. Default 5MB, pas aan met -XX:NonNMethodCodeHeapSize.

nonheap_profiled_nmethods: A profiled code heap containing lightly optimized, profiled methods with a short lifetime. Default 122MB, pas aan met -XX:ProfiledCodeHeapSize.

nonheap_non_profiled_nmethods: A non-profiled code heap containing fully optimized, non-profiled methods with a potentially long lifetime. Default 122MB, pas aan met -XX:NonProfiledCodeHeapSize.

Elk deel geheugen heeft een used, comitted en max size. 
De used size is het huidige gebruik. De max size is de max size, maar die waarde is niet gegarandeerd beschikbaar. De committed size is de size die gegarandeerd voor de jvm beschikbaar is.

Links

https://dzone.com/articles/understanding-the-java-memory-model-and-the-garbag
https://www.baeldung.com/java-heap-used-committed-max
https://www.baeldung.com/jvm-code-cache
https://stackoverflow.com/questions/59189225/in-java-memory-pool-what-is-the-replacement-of-code-cache-replacement-in-java-11

Mutual SSL authentication

In deze blog laat ik zien wat de stappen zijn om certificaten te maken voor server en client applicaties.

Voor testen kun je de key- en trust stores maken zonder CA. Op productie zal er altijd een CA tussen zitten. Beide manieren worden hieronder besproken.

Een demo project met een server en client die ssl gebruiken (ook als authenticatie) is hier te vinden:

https://github.com/robbertvdzon/clientcertificateexample

Lees meer »

Going springless: no more magic!

Working with Spring Boot (but also working with JEE/Jakarta EE) can be a joyful experience. Within minutes you can create a  new RESTfull webservice  to which you can quickly and easily add circuit breakers, distributed tracing, security, database access, accessing other microservices, fallbacks, retries, service discovery, configuration management, many other things and of course you can use the great Spring DI framework.

Lees meer »

List of Spring Boot Starter Dependencies

[Index of Spring blogs]

Core:

Lees meer »

Testing the Spring MVC layer

[Index of Spring blogs]

Use “spring-boot-starter-test” to add all dependencies:

    org.springframework.boot
    spring-boot-starter-test
    test

You can annotate the test class with :

  • (nothing)
  • @SpringBootTest(webEnvironment = MOCK / RANDOM_PORT / DEFINED_PORT)
  • @AutoConfigureMockMvc
  • @WebMvcTest

To make rest call’s to the controllers, you can use one of the following:

  • RestTemplate
  • TestRestTemplate
  • RestAssuredMockMvc
  • MockMvc
  • WebTestClient (only when using webflux)

@SpringBootTest will load your complete Spring application, but without the Servlet container when specifying (webEnvironment = MOCK).
When using webEnvironment = RANDOM_PORT, a random port is used (which you can find in the test using @LocalServerPort).
It is also possible to autowire a TestRestTemplate, RestAssuredMockMvc or MockMvc which you can use to test the application using relative url’s.

@MockBean can be used to mock any bean in the application environment.

To test the serialization and deserialization of a JSON object, you can use @JsonTest

To test a web client, you can use @RestClientTest

Examples of using the different annotations and rest clients can be found below:

Lees meer »

Spring WebFlux samples and links

[Index of Spring blogs]

Samples:
https://github.com/robbertvdzon/springfluxsamples/blob/master/src/main/java/com/example/springwebflux/SpringwebfluxApplication.java

Spring5 documentation about webFlux:
https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux

Spring Boot documentation about webFlux:
https://docs.spring.io/spring-boot/docs/2.1.0.RELEASE/reference/htmlsingle/#boot-features-webflux

Spring testing documentation about Spring Web Reactive:
https://docs.spring.io/spring/docs/current/spring-framework-reference/testing.html#mock-objects-web-reactive

 

Spring WebMVC samples and links

[Index of Spring blogs]

Samples:
https://github.com/robbertvdzon/spring-web-mvc-samples/blob/master/src/main/java/com/example/demo/DemoApplication.java

Spring5 documentation about webMVC:
https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html

Spring Boot documentation about webMVC:
https://docs.spring.io/spring-boot/docs/2.1.0.RELEASE/reference/htmlsingle/#boot-features-developing-web-applications

Spring testing documentation about MVC Test Framework:
https://docs.spring.io/spring/docs/current/spring-framework-reference/testing.html#spring-mvc-test-framework