Giter Club home page Giter Club logo

Comments (6)

jptosso avatar jptosso commented on September 3, 2024 1

It's cool, thank you for your discovery, I will close this issue once a solution is found, so you are kept posted.

from coraza-caddy.

jptosso avatar jptosso commented on September 3, 2024 1

Hey @abstractvector, I have added a new cache feature for transactions so the memory is reused instead of freed and reallocated, your feedback on the branch would be really appreciated: https://github.com/jptosso/coraza-caddy/tree/tx_clean (132f1f6)

My results are a 0,3% (96MB) variation of memory with 100.000 requests:

Concurrency Level:      100
Time taken for tests:   35.207 seconds
Complete requests:      100000
Failed requests:        0
Total transferred:      10400000 bytes
HTML transferred:       1300000 bytes
Requests per second:    2840.36 [#/sec] (mean)
Time per request:       35.207 [ms] (mean)
Time per request:       0.352 [ms] (mean, across all concurrent requests)
Transfer rate:          288.47 [Kbytes/sec] received

Thank you

from coraza-caddy.

jptosso avatar jptosso commented on September 3, 2024

Hey @abstractvector thank you very much for the information and the docker implementation, the memory footprint of the rules cannot be decreased a lot, but I will run some tests.

Regarding the transactions, maybe the GC is not fast enough to clear old transactions, I will run some experiments with a transaction.Close function to flush resources.

Can you provide me your hardware specs and the parameters used for AB? I will try to replicate the issue and create a detailed profiling.

from coraza-caddy.

abstractvector avatar abstractvector commented on September 3, 2024

My testing was crude and not particularly extensive, but the following command demonstrates the issue quite well:

$ ab -c 100 -n 10000 http://localhost:8000

Running this against either your Docker image with CRS compiled in or my Docker image linked above shows the situation quite clearly in contrast to the same test with the two CRS config file lines commented out. I'm just running this on a MacBook Pro - Docker has access to 4 CPUs and 2GB RAM.

Having now left it a while, it seems like the memory consumption does eventually drop - it looks like a minute or two after the ab run, the CPU usage for the process jumps to around 11-12% and the memory consumption begins dropping. I'm guessing that's the GC.

My hope is to turn this into a cross-platform build so it could run on a Raspberry Pi or similar, but that memory consumption is too high unfortunately.

from coraza-caddy.

jptosso avatar jptosso commented on September 3, 2024

You are right about the memory spike but the GC turns down after a few seconds. It should be a priority to reduce the effort for the GC and proposals are more than welcome. I think I should create a function after tx.ProcessLogging(), something like tx.Close()

func (tx *Transaction) Close() error {
  if tx.collections == nil {
    return fmt.Errorf("transaction already closed")
  tx.collections = nil
}

or manually clearing it:

for k := range tx.collections {
    delete(tx.collections, k)
}

tx.collections is the heavier pointer for a transaction, forcing it's deletion should be enough.

from coraza-caddy.

abstractvector avatar abstractvector commented on September 3, 2024

I would love to help out, but I know very little about Go so I'm unlikely to be much assistance I'm afraid.

from coraza-caddy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.