forked from apache/atlas
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce atlas startupTime : enable debug logs, reduce indeex queries
- Loading branch information
1 parent
aaa1102
commit 8a665c4
Showing
8 changed files
with
139 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
repository/src/main/java/org/apache/atlas/repository/audit/StartupTimeLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.apache.atlas.repository.audit; | ||
|
||
import org.apache.atlas.type.AtlasType; | ||
import org.apache.atlas.utils.AtlasPerfTracer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Component | ||
public class StartupTimeLogger implements ApplicationListener<ContextRefreshedEvent> { | ||
private final StartupTimeLoggerBeanPostProcessor beanPostProcessor; | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(StartupTimeLogger.class); | ||
|
||
public StartupTimeLogger(StartupTimeLoggerBeanPostProcessor beanPostProcessor) { | ||
this.beanPostProcessor = beanPostProcessor; | ||
} | ||
|
||
@Override | ||
public void onApplicationEvent(ContextRefreshedEvent event) { | ||
// Print the startup times after all beans are loaded | ||
printHashMapInTableFormatDescendingOrder(beanPostProcessor.getDurationTimeMap()); | ||
} | ||
|
||
public static void printHashMapInTableFormatDescendingOrder(Map<String, Long> map) { | ||
// Convert map to a list of entries | ||
List<Map.Entry<String, Long>> list = new ArrayList<>(map.entrySet()); | ||
|
||
// Sort the list by values in descending order | ||
list.sort((entry1, entry2) -> entry2.getValue().compareTo(entry1.getValue())); | ||
LOG.info("Capturing Bean creation time {}", AtlasType.toJson(list)); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...y/src/main/java/org/apache/atlas/repository/audit/StartupTimeLoggerBeanPostProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.apache.atlas.repository.audit; | ||
|
||
import org.apache.atlas.utils.AtlasPerfTracer; | ||
import org.slf4j.Logger; | ||
import org.springframework.beans.factory.config.BeanPostProcessor; | ||
import org.springframework.stereotype.Component; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Component | ||
public class StartupTimeLoggerBeanPostProcessor implements BeanPostProcessor { | ||
private final Map<String, Long> startTimeMap = new HashMap<>(); | ||
|
||
public Map<String, Long> getDurationTimeMap() { | ||
return durationTimeMap; | ||
} | ||
|
||
private final Map<String, Long> durationTimeMap = new HashMap<>(); | ||
|
||
private static final Logger PERF_LOG = AtlasPerfTracer.getPerfLogger("Beans"); | ||
|
||
private AtlasPerfTracer perf = null; | ||
|
||
@Override | ||
public Object postProcessBeforeInitialization(Object bean, String beanName) { | ||
// Record the start time | ||
startTimeMap.put(bean.getClass().getName(), System.currentTimeMillis()); | ||
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { | ||
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "Beans.create(" + beanName + ")"); | ||
} | ||
return bean; | ||
} | ||
|
||
@Override | ||
public Object postProcessAfterInitialization(Object bean, String beanName) { | ||
AtlasPerfTracer.log(perf); | ||
// Calculate and log the startup time | ||
long startTime = startTimeMap.getOrDefault(bean.getClass().getName(), -1L); | ||
long endTime = System.currentTimeMillis(); | ||
if (startTime != -1L) { | ||
durationTimeMap.put(bean.getClass().getName(), endTime-startTime); | ||
} | ||
return bean; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters