smocker-dev / smocker

Smocker is a simple and efficient HTTP mock server and proxy
https://smocker.dev
MIT License
1.13k stars 59 forks source link

Ability to Delete Mocks #303

Open joshua-temple opened 3 months ago

joshua-temple commented 3 months ago

Howdy!

TLDR; Smocker appears to be increasing in CPU utilization as my integration suite grows. Having the ability to remove orphaned mocks may alleviate this.

First off, I saw this other issue that brought up edit/deletion of mocks, and the response therein.

However, my use case is different and wanted to at least plant the seed of hope.

I'm leveraging your wonderful service as a go-between for my integration suite.

The suite spins up all the necessary infra, including smocker, and then runs tests against those services.

Smocker acts as the dependency gap coverage, so each service in the infra points to smocker in place of an actual API dependency.

So when a single test initiates, the mocks it requires are posted to smocker and then the test runs.

As the suite grows (~150 tests), so does the amount of mocks smocker ingests and thus increases CPU utilization.

This is where my need to remove mocks comes into play, but I may be making an erroneous assumption that more mocks == more CPU util.

When a test completes, I'd like to dump those mocks to reduce overhead.

If this were a synchronous test suite, it'd be a non-issue, simply reset between tests. However, that would make test execution likely run for hours so that is not an option.

Worst comes to worse, I can roll my own delete endpoint into it, but obviously not an encouraged practice for several reasons.

Thoughts?

gwleclerc commented 3 months ago

Hi, I have some questions:

Currently Smocker is not necessarily optimized. It loads everything in memory and simply loops over each mock of the current session every time it receives a call. You can see it here: https://github.com/smocker-dev/smocker/blob/main/server/handlers/mocks.go#L53

This can be optimized using go routines to retrieve matched mocks faster but I'm not sure it will reduce the CPU usage.

joshua-temple commented 3 months ago

@gwleclerc thank you for the reply!

Do you use sessions ?

Currently not using sessions, as to my understanding, you can only use a single session at a time.

How many mocks are load per session during your 150 tests ?

I'd guesstimate somewhere around ~20 mocks per test, each being unique mocks.

While there are varying degrees of overlap between mocks, between tests, they are ultimately unique in smocker's eyes.

Do you have any memory issue ?

We did at first, but set a static retention value as we aren't currently interested in validating the mock payload was as expected, because we're inherently validating that with downstream changes in the logic. If the mock didn't return as expected, the data after the fact wouldn't be shaped as expected.

How many calls does it receive at the same time?

Thats a tough gauge but I will look into how I can assert that for you and get back to you asap.