-
Notifications
You must be signed in to change notification settings - Fork 85
Implementing a PID per pod #931
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
Draft
kris-gaudel
wants to merge
10
commits into
pid-take-2
Choose a base branch
from
kris-gaudel/poc-pid-per-pod
base: pid-take-2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ba373e3
update Gemfile with async gems
kris-gaudel 9fc13e0
implement WAL
kris-gaudel 8129416
PID state service
kris-gaudel 2fbc697
implement state service, bus controller and methods for RPC
kris-gaudel 1d9f182
default config for PID
kris-gaudel 54d0825
implement services for PID state
kris-gaudel 932fe65
integrate pod ACB into Semian
kris-gaudel f2bb2a2
implement example
kris-gaudel 47b832c
replace comment with nil
kris-gaudel 5fe34f7
only load `PodAdaptiveCircuitBreaker` when used, minor linting
kris-gaudel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/usr/bin/env async-service | ||
| # frozen_string_literal: true | ||
|
|
||
| require "bundler/setup" | ||
| require "async/container/supervisor" | ||
| require "semian" | ||
| require "semian/pod_pid" | ||
| require "semian/pod_pid/service" | ||
|
|
||
| service "pid-state-service" do | ||
| service_class Semian::PodPID::Service | ||
| include Async::Container::Supervisor::Supervised | ||
| end | ||
|
|
||
| service "supervisor" do | ||
| include Async::Container::Supervisor::Environment | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| #!/usr/bin/env ruby | ||
| # frozen_string_literal: true | ||
|
|
||
| require "bundler/setup" | ||
| require "semian" | ||
| require "semian/pod_pid" | ||
| require "async" | ||
| require "async/bus/server" | ||
|
|
||
| NUM_WORKERS = 4 | ||
| PHASES = [ | ||
| { name: "Phase 1: Healthy Service", count: 100, success_rate: 1.0 }, | ||
| { name: "Phase 2: Degraded Service", count: 200, success_rate: 0.5 }, | ||
| { name: "Phase 3: Failing Service", count: 200, success_rate: 0.0 }, | ||
| { name: "Phase 4: Service Recovery", count: 300, success_rate: 1.0 }, | ||
| ].freeze | ||
|
|
||
| def run_worker(worker_id, phase_pipe_read, result_pipe_write) | ||
| Sync do |task| | ||
| client = Semian::PodPID::Client.new | ||
| client.connect | ||
|
|
||
| result_pipe_write.puts("READY") | ||
|
|
||
| while (line = phase_pipe_read.gets) | ||
| phase = line.strip.split(",") | ||
| break if phase[0] == "DONE" | ||
|
|
||
| count = phase[1].to_i | ||
| success_rate = phase[2].to_f | ||
|
|
||
| stats = { success: 0, error: 0, rejected: 0 } | ||
|
|
||
| count.times do |i| | ||
| task.sleep(0.001) if (i % 10).zero? | ||
|
|
||
| if client.should_reject?("mysql") | ||
| client.record_observation("mysql", :rejected) | ||
| stats[:rejected] += 1 | ||
| elsif rand < success_rate | ||
| client.record_observation("mysql", :success) | ||
| stats[:success] += 1 | ||
| else | ||
| client.record_observation("mysql", :error) | ||
| stats[:error] += 1 | ||
| end | ||
| end | ||
|
|
||
| task.sleep(0.1) | ||
| result_pipe_write.puts("#{stats[:success]},#{stats[:error]},#{stats[:rejected]},#{client.rejection_rate("mysql")}") | ||
| end | ||
|
|
||
| client.disconnect | ||
| end | ||
| exit!(0) | ||
| end | ||
|
|
||
| puts "=== Pod Adaptive Circuit Breaker Demo (Multi-Process) ===\n\n" | ||
|
|
||
| server_ready_read, server_ready_write = IO.pipe | ||
|
|
||
| server_pid = fork do | ||
| server_ready_read.close | ||
|
|
||
| Sync do |task| | ||
| state_service = Semian::PodPID::StateService.new( | ||
| kp: Semian::DEFAULT_PID_CONFIG[:kp], | ||
| ki: Semian::DEFAULT_PID_CONFIG[:ki], | ||
| kd: Semian::DEFAULT_PID_CONFIG[:kd], | ||
| window_size: Semian::DEFAULT_PID_CONFIG[:window_size], | ||
| sliding_interval: Semian::DEFAULT_PID_CONFIG[:sliding_interval], | ||
| initial_error_rate: Semian::DEFAULT_PID_CONFIG[:initial_error_rate], | ||
| ) | ||
|
|
||
| controller = Semian::PodPID::Controller.new(state_service) | ||
| server = Async::Bus::Server.new | ||
|
|
||
| task.async do | ||
| server.accept do |connection| | ||
| connection.bind(:pid_controller, controller) | ||
| end | ||
| end | ||
|
|
||
| task.async do | ||
| loop do | ||
| task.sleep(0.05) | ||
| state_service.update_all_resources | ||
| end | ||
| end | ||
|
|
||
| server_ready_write.puts("READY") | ||
| server_ready_write.close | ||
|
|
||
| sleep | ||
| end | ||
| end | ||
|
|
||
| server_ready_write.close | ||
| server_ready_read.gets | ||
| puts "PID state service started (PID: #{server_pid})\n\n" | ||
|
|
||
| workers = [] | ||
| phase_pipes = [] | ||
| result_pipes = [] | ||
|
|
||
| NUM_WORKERS.times do |i| | ||
| phase_read, phase_write = IO.pipe | ||
| result_read, result_write = IO.pipe | ||
|
|
||
| pid = fork do | ||
| phase_write.close | ||
| result_read.close | ||
| run_worker(i + 1, phase_read, result_write) | ||
| end | ||
|
|
||
| phase_read.close | ||
| result_write.close | ||
|
|
||
| workers << pid | ||
| phase_pipes << phase_write | ||
| result_pipes << result_read | ||
| end | ||
|
|
||
| puts "Waiting for #{NUM_WORKERS} worker processes to connect..." | ||
| result_pipes.each(&:gets) | ||
| puts "All workers connected!\n\n" | ||
|
|
||
| PHASES.each do |phase| | ||
| puts "#{phase[:name]} (#{phase[:count]} requests per worker)" | ||
| puts "-" * 50 | ||
|
|
||
| phase_pipes.each do |pipe| | ||
| pipe.puts("PHASE,#{phase[:count]},#{phase[:success_rate]}") | ||
| end | ||
|
|
||
| total = { success: 0, error: 0, rejected: 0 } | ||
| rates = [] | ||
|
|
||
| result_pipes.each_with_index do |pipe, i| | ||
| result = pipe.gets.strip.split(",") | ||
| total[:success] += result[0].to_i | ||
| total[:error] += result[1].to_i | ||
| total[:rejected] += result[2].to_i | ||
| rates << result[3].to_f | ||
| puts " Worker #{i + 1} (PID #{workers[i]}): #{result[0]} success, #{result[1]} errors, #{result[2]} rejected, rate=#{(result[3].to_f * 100).round(2)}%" | ||
| end | ||
|
|
||
| puts " Total: #{total[:success]} success, #{total[:error]} errors, #{total[:rejected]} rejected" | ||
| puts " All workers synchronized: #{rates.uniq.size == 1}\n\n" | ||
| end | ||
|
|
||
| puts "=== Demo Complete ===\n" | ||
|
|
||
| phase_pipes.each do |pipe| | ||
| pipe.puts("DONE") | ||
| pipe.close | ||
| end | ||
| result_pipes.each(&:close) | ||
|
|
||
| sleep(0.5) | ||
|
|
||
| (workers + [server_pid]).each do |pid| | ||
| Process.kill("KILL", pid) | ||
| rescue | ||
| nil | ||
| end | ||
|
|
||
| Process.waitall |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was changed by the linter, not related to the the functionality of this PR