amazon-web-servicesspring-bootout-of-memorymicroservicesnetflix-eureka

Eureka Server memory, renew threshold is 0, self preservation issue - AWS


I deployed 2 instances of Eureka server and a total of 12 instances microservices. enter image description here.

Renews (last min) is as expected 24. But Renew Threshold is always 0. Is this how it supposed to be when self preservation is turned on? Also seeing this error - THE SELF PRESERVATION MODE IS TURNED OFF. THIS MAY NOT PROTECT INSTANCE EXPIRY IN CASE OF NETWORK/OTHER PROBLEMS. What's the expected behavior in this case and how to resolve this if this is a problem? enter image description here

As mentioned above, I deployed 2 instances of Eureka Server but after running for a while like around 19-20 hours, one instance of Eureka Server always goes down. Why that could be possibly happening? I checked the processes running using top command and found that Eureka Server is taking a lot of memory. What needs to be configured on Eureka Server so that it don't take a lot of memory?

Below is the configuration in the application.properties file of Eureka Server:

spring.application.name=eureka-server
eureka.instance.appname=eureka-server
eureka.instance.instance-id=${spring.application.name}:${spring.application.instance_id:${random.int[1,999999]}}
eureka.server.enable-self-preservation=false
eureka.datacenter=AWS
eureka.environment=STAGE

eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false

Below is the command that I am using to start the Eureka Server instances.

#!/bin/bash
java -Xms128m -Xmx256m -Xss256k -XX:+HeapDumpOnOutOfMemoryError -Dspring.profiles.active=stage -Dserver.port=9011 -Deureka.instance.prefer-ip-address=true -Deureka.instance.hostname=example.co.za -Deureka.client.serviceUrl.defaultZone=http://example.co.za:9012/eureka/ -jar eureka-server-1.0.jar &
java -Xms128m -Xmx256m -Xss256k -XX:+HeapDumpOnOutOfMemoryError -Dspring.profiles.active=stage -Dserver.port=9012 -Deureka.instance.prefer-ip-address=true -Deureka.instance.hostname=example.co.za -Deureka.client.serviceUrl.defaultZone=http://example.co.za:9011/eureka/ -jar eureka-server-1.0.jar &

Is this approach to create multiple instances of Eureka Server correct?

Deployment is on AWS. Is there any specific configuration needed for Eureka Server on AWS?

Spring Boot version: 2.3.4.RELEASE


Solution

  • Let me try to answer your question one by one.

    Renews (last min) is as expected 24. But Renew Threshold is always 0. Is this how it supposed to be when self-preservation is turned on? What's the expected behaviour in this case and how to resolve this if this is a problem?

    I can see that eureka.server.enable-self-preservation=false in your configuration, This is really needed if you want to remove an already registered application as soon as it fails to renew its lease.

    Self-preservation feature is to prevent the above-mentioned situation since it can happen if there are some network hiccups. Say, you have two services A and B, both are registered to eureka and suddenly, B failed to renew its lease because of a temporary network hiccup. If Self-preservation is not there then B will be removed from the registry and A won't be able to reach B despite B is available. So we can say that Self-preservation is a resiliency feature of eureka.

    Renews threshold is the expected renews per minute, Eureka server enters self-preservation mode if the actual number of heartbeats in last minute(Renews) is less than the expected number of renews per minute(Renew Threshold) and Of course, you can control the Renews threshold. you can configure renewal-percent-threshold (by default it is 0.85)

    So in your case,

    Total number of application instances = 12

    You don't have eureka.instance.leaseRenewalIntervalInSeconds so default value 30s and eureka.client.registerWithEureka=false

    so Renewals(last minute) will be 24

    You don't have renewal-percent-threshold configured, so the default value is 0.85 Number of renewals per application instance per minute = 2 (30s each)

    so in case of self-preservation is enable Renews threshold will be calculated as 2 * 12 * 0.85 = 21 (rounded)

    And in your case self-preservation is turned off, so Eureka won't calculate Renews Threshold

    One instance of Eureka Server always goes down. Why that could be possibly happening?

    I'm not able to answer this question time being, this can be because of multiple reasons. You can find the reason mostly from logs, or if you can post logs here it would be great.

    What needs to be configured on Eureka Server so that it doesn't take a lot of memory?

    From the information that you have provided, I cannot tell about your memory issue and in addition to that you already specified -Xmx256m and I didn't face any memory issues with the eureka servers so far.

    But I can say that top is not the right tool for checking the memory consumed by your java process. When JVM starts, It takes some memory from the operating system. This is the amount of memory you see in tools like ps and top. so better use jstat or jvmtop

    Is this approach to create multiple instances of Eureka Server correct?

    It seems you are having the same hostname(eureka.instance.hostname) for both instances. Replication won't work if you use the same hostname. And make sure that you have the same application names in both instances.

    Deployment is on AWS. Is there any specific configuration needed for Eureka Server on AWS?

    Nothing specifically for AWS as per my knowledge, other than making sure that the instances can communicate with each other.