Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add performance problems; Minor bugfixes #11

Open
wants to merge 6 commits into
base: inspectit
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ You can then access petclinic here: http://localhost:8080/

Our issue tracker is available here: https://github.com/spring-petclinic/spring-petclinic-microservices/issues


## Performance "problems"
This extension includes some very simple performance problems on purpose to visualize how APM tools can
detect these and show them to the user.

- Creating a new pet with the type Snake will impose a 2s delay.
- Finding a customer with a customer ID that can be divided by 11 will impose a 1s delay.
- Loading the visits will impose 2s delay with a probability of 10 percent.

## Intellij setup

- Please make sure to install the Lombok Plugin
## Database configuration

In its default configuration, Petclinic uses an in-memory database (HSQLDB) which
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ zuul:
visits-service: /visit/**
customers-service: /customer/**
api-gateway: /gateway/**
hystrix:
command:
default:
execution:
timeout:
enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.*;

import javax.validation.Valid;

Expand Down Expand Up @@ -57,7 +54,7 @@ class OwnerResource {
private final OwnerRepository ownerRepository;

private final ExecutorService executor = Executors.newCachedThreadPool();

/**
* Create Owner
*/
Expand All @@ -73,6 +70,16 @@ public void createOwner(@Valid @RequestBody Owner owner) {
*/
@GetMapping(value = "/{ownerId}")
public Owner findOwner(@PathVariable("ownerId") int ownerId) {

// introduce some performance problem (in the most easy way)
if (ownerId % 11 == 0) {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

return ownerRepository.findOne(ownerId);
}

Expand All @@ -87,7 +94,7 @@ public List<Owner> call() throws Exception {
return ownerRepository.findAll();
}
});

try {
return future.get();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
* @author Juergen Hoeller
Expand Down Expand Up @@ -63,6 +64,15 @@ public void processCreationForm(
@ResponseStatus(HttpStatus.NO_CONTENT)
@Monitored
public void processUpdateForm(@RequestBody PetRequest petRequest) {
// only do that is we have a "Snake" (type 4)
if (petRequest.getTypeId() == 4) {
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

save(petRepository.findOne(petRequest.getId()), petRequest);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import javax.validation.Valid;
import java.util.List;
import java.util.Random;

/**
* @author Juergen Hoeller
Expand Down Expand Up @@ -53,6 +54,16 @@ public void create(

@GetMapping("owners/*/pets/{petId}/visits")
public List<Visit> visits(@PathVariable("petId") int petId) {

// lets spice things a bit up and sometimes integrate some longer load times
if (Math.random() < 0.1) {
try {
Thread.currentThread().sleep(2000);
} catch (InterruptedException e) {
// ignore
}
}

return visitRepository.findByPetId(petId);
}
}
2 changes: 1 addition & 1 deletion start_all_with_inspectIT.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rem !!!!do not use spaces in the path of inspectIT installation folder!!!!
set AGENTDIR=%1
set WAITTIME=5
set /a "x = 0"

set PATH=%PATH%;C:\windows\system32;
rem STARTTYPE, z.B. /B = start without open a new windows, /MIN start minized in new windows
set STARTTYPE=/B

Expand Down