I have a Spring 4.3.6 App running on backend with Angular 2 on frontend. Every time after the server is initialized, the first request the server responds have a high TTFB (time to first byte), if compared with the subsequent requests.TTFB delay on the first request
I verified that right on the first request I got a high peak in my computer's processor. Below is my login method in my UserController:
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(@RequestBody Map<String, String> json) throws ServletException {
if (json.get("stUserLogin") == null || json.get("stUserPassword") == null) {
throw new ServletException("...");
}
String userLogin = json.get("stUserLogin");
String userPassword = json.get("stUserPassword");
UserBean userBean = userService.findByUserLogin(userLogin);
if (userBean == null) {
throw new ServletException("...");
}
if (!userPassword.equals(userBean.getStUserPassword())) {
throw new ServletException("...");
}
return Jwts.builder().setSubject(userLogin).claim("roles", "user").setIssuedAt(new Date())
.signWith(SignatureAlgorithm.HS256, "secretkey").compact();
}
This is my UserService's find user method:
@Override
public UserBean findByUserLogin(String stUserLogin) {
return userDAO.findByStUserLogin(stUserLogin);
}
And finally my DAO's method:
UserBean findByStUserLogin(String stUserLogin);
On the first request, I verified a high amount of milliseconds expended in the Service's method, but I still have no clue about the reason behind all this.
It is worth mentioning that this happens with every mapped method, but with different scales.
I don't know if I provided enough information about this issue. Any help will be well received, thank you in advance.