Leak memory, spin cpu and kill the process
This commit is contained in:
parent
cfe3cfb370
commit
83dc8f1c66
2 changed files with 26 additions and 0 deletions
|
@ -1,9 +1,32 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ChaosController < ActionController::Base
|
||||
def leakmem
|
||||
memory_mb = params[:memory_mb] ? params[:memory_mb].to_i : 100
|
||||
retainer = []
|
||||
|
||||
memory_mb.times { retainer << "x" * (1024 * 1024) }
|
||||
render text: "OK", content_type: 'text/plain'
|
||||
end
|
||||
|
||||
def cpuspin
|
||||
duration_s = params[:duration_s] ? params[:duration_s].to_i : 30
|
||||
end_time = Time.now + duration_s.seconds;
|
||||
while Time.now < end_time
|
||||
10_000.times { }
|
||||
end
|
||||
|
||||
render text: "OK", content_type: 'text/plain'
|
||||
end
|
||||
|
||||
def sleep
|
||||
duration_s = params[:duration_s] ? params[:duration_s].to_i : 30
|
||||
Kernel.sleep duration_s
|
||||
render text: "OK", content_type: 'text/plain'
|
||||
end
|
||||
|
||||
def kill
|
||||
Process.kill("KILL", Process.pid)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -83,7 +83,10 @@ Rails.application.routes.draw do
|
|||
draw :operations
|
||||
draw :instance_statistics
|
||||
|
||||
get '/chaos/leakmem' => 'chaos#leakmem'
|
||||
get '/chaos/cpuspin' => 'chaos#cpuspin'
|
||||
get '/chaos/sleep' => 'chaos#sleep'
|
||||
get '/chaos/kill' => 'chaos#kill'
|
||||
end
|
||||
|
||||
draw :api
|
||||
|
|
Loading…
Reference in a new issue