giving some frash air to cpu
This commit is contained in:
parent
f11408a3d2
commit
b32d69b9d0
5 changed files with 22 additions and 38 deletions
|
@ -14,8 +14,8 @@ services:
|
||||||
deploy:
|
deploy:
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
cpus: "0.30"
|
cpus: "0.50"
|
||||||
memory: "330MB"
|
memory: "10MB"
|
||||||
zig1: &zig
|
zig1: &zig
|
||||||
container_name: zig-pay-1
|
container_name: zig-pay-1
|
||||||
build: .
|
build: .
|
||||||
|
@ -23,7 +23,7 @@ services:
|
||||||
- SERVER_ENV=PROD
|
- SERVER_ENV=PROD
|
||||||
- DEFAULT_HOST=payment-processor-default
|
- DEFAULT_HOST=payment-processor-default
|
||||||
- DEFAULT_PORT=8080
|
- DEFAULT_PORT=8080
|
||||||
- DEFAULT_POOL=30
|
- DEFAULT_POOL=20
|
||||||
- FALLBACK_HOST=payment-processor-fallback
|
- FALLBACK_HOST=payment-processor-fallback
|
||||||
- FALLBACK_PORT=8080
|
- FALLBACK_PORT=8080
|
||||||
- FALLBACK_POOL=0
|
- FALLBACK_POOL=0
|
||||||
|
@ -35,7 +35,7 @@ services:
|
||||||
deploy:
|
deploy:
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
cpus: "0.60"
|
cpus: "0.50"
|
||||||
memory: "10MB"
|
memory: "10MB"
|
||||||
zig2:
|
zig2:
|
||||||
<<: *zig
|
<<: *zig
|
||||||
|
@ -44,7 +44,7 @@ services:
|
||||||
- SERVER_ENV=PROD
|
- SERVER_ENV=PROD
|
||||||
- DEFAULT_HOST=payment-processor-default
|
- DEFAULT_HOST=payment-processor-default
|
||||||
- DEFAULT_PORT=8080
|
- DEFAULT_PORT=8080
|
||||||
- DEFAULT_POOL=30
|
- DEFAULT_POOL=20
|
||||||
- FALLBACK_HOST=payment-processor-fallback
|
- FALLBACK_HOST=payment-processor-fallback
|
||||||
- FALLBACK_PORT=8080
|
- FALLBACK_PORT=8080
|
||||||
- FALLBACK_POOL=0
|
- FALLBACK_POOL=0
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
worker_processes auto;
|
worker_processes auto;
|
||||||
worker_rlimit_nofile 500000;
|
worker_rlimit_nofile 100000;
|
||||||
|
|
||||||
events {
|
events {
|
||||||
use epoll;
|
use epoll;
|
||||||
worker_connections 1024;
|
worker_connections 550;
|
||||||
}
|
}
|
||||||
http {
|
http {
|
||||||
access_log off;
|
access_log off;
|
||||||
|
@ -12,16 +12,13 @@ http {
|
||||||
upstream backend_servers {
|
upstream backend_servers {
|
||||||
server zig1:8080;
|
server zig1:8080;
|
||||||
server zig2:8080;
|
server zig2:8080;
|
||||||
keepalive 200;
|
keepalive 500;
|
||||||
}
|
}
|
||||||
server {
|
server {
|
||||||
listen 9999;
|
listen 9999;
|
||||||
location / {
|
location / {
|
||||||
proxy_buffering off;
|
proxy_buffering off;
|
||||||
proxy_set_header Connection "";
|
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Keep-Alive "";
|
|
||||||
proxy_set_header Proxy-Connection "keep-alive";
|
|
||||||
proxy_pass http://backend_servers;
|
proxy_pass http://backend_servers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,13 +24,6 @@ pub fn registerEndpoints(get_endpoints: *EndpointsManager, post_endpoints: *Endp
|
||||||
}
|
}
|
||||||
|
|
||||||
fn postPayments(req: *Request, res: *Response) void {
|
fn postPayments(req: *Request, res: *Response) void {
|
||||||
if (ctx.server_settings.failure)
|
|
||||||
return res.withStatus(.service_unavailable).end();
|
|
||||||
|
|
||||||
if (ctx.server_settings.delay > 0) {
|
|
||||||
std.time.sleep(ctx.server_settings.delay * std.time.ns_per_ms);
|
|
||||||
}
|
|
||||||
|
|
||||||
res.withStatus(.unprocessable_entity).withContentType(.json).end();
|
res.withStatus(.unprocessable_entity).withContentType(.json).end();
|
||||||
|
|
||||||
var prop_correlationId = parses.PropertySpec{ .name = "correlationId" };
|
var prop_correlationId = parses.PropertySpec{ .name = "correlationId" };
|
||||||
|
@ -54,13 +47,6 @@ fn postPayments(req: *Request, res: *Response) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getPaymentsById(req: *Request, res: *Response) void {
|
fn getPaymentsById(req: *Request, res: *Response) void {
|
||||||
if (ctx.server_settings.failure)
|
|
||||||
return res.withStatus(.service_unavailable).end();
|
|
||||||
|
|
||||||
if (ctx.server_settings.delay > 0) {
|
|
||||||
std.time.sleep(ctx.server_settings.delay * std.time.ns_per_ms);
|
|
||||||
}
|
|
||||||
|
|
||||||
const template_json_res: []const u8 =
|
const template_json_res: []const u8 =
|
||||||
\\{{
|
\\{{
|
||||||
\\ "correlationId": "{s}",
|
\\ "correlationId": "{s}",
|
||||||
|
@ -93,8 +79,8 @@ fn getPaymentsById(req: *Request, res: *Response) void {
|
||||||
|
|
||||||
const template_json_summary: []const u8 =
|
const template_json_summary: []const u8 =
|
||||||
\\{{
|
\\{{
|
||||||
\\ "default": {{ "totalRequests": "{d}", "totalAmount": {d:.2} }},
|
\\ "default": {{ "totalRequests": {d}, "totalAmount": {d:.2} }},
|
||||||
\\ "fallback": {{ "totalRequests": "{d}", "totalAmount": {d:.2} }}
|
\\ "fallback": {{ "totalRequests": {d}, "totalAmount": {d:.2} }}
|
||||||
\\}}
|
\\}}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ const DateTime = @import("things").DateTime;
|
||||||
|
|
||||||
const is_test = @import("builtin").is_test;
|
const is_test = @import("builtin").is_test;
|
||||||
|
|
||||||
const MAX_QUEUE_SIZE = if (is_test) 100 else 500_000;
|
const MAX_QUEUE_SIZE = if (is_test) 100 else 100_000;
|
||||||
const MAX_RETRY = if (is_test) 2 else 10_000_000;
|
const MAX_RETRY = if (is_test) 2 else 10_000_000;
|
||||||
|
|
||||||
const PaymentIntegration = struct {
|
const PaymentIntegration = struct {
|
||||||
|
@ -53,7 +53,7 @@ pub const PaymentIntegrator = struct {
|
||||||
|
|
||||||
fn startProcess(self: *PaymentIntegrator) void {
|
fn startProcess(self: *PaymentIntegrator) void {
|
||||||
while (true) {
|
while (true) {
|
||||||
Thread.sleep(1_000_000);
|
Thread.sleep(10_000_000);
|
||||||
|
|
||||||
self.verifyTailSize();
|
self.verifyTailSize();
|
||||||
self.processPayments();
|
self.processPayments();
|
||||||
|
|
|
@ -31,7 +31,7 @@ pub const HttpService = struct {
|
||||||
|
|
||||||
health_connection: ServiceConnection = ServiceConnection{},
|
health_connection: ServiceConnection = ServiceConnection{},
|
||||||
capacity: usize = 0,
|
capacity: usize = 0,
|
||||||
health: ServiceHealth = .unavailable,
|
health: ServiceHealth = .available,
|
||||||
response_time: u64 = 0,
|
response_time: u64 = 0,
|
||||||
|
|
||||||
mutex: Mutex,
|
mutex: Mutex,
|
||||||
|
@ -48,11 +48,11 @@ pub const HttpService = struct {
|
||||||
|
|
||||||
var final_addr: ?Address = null;
|
var final_addr: ?Address = null;
|
||||||
for (addrList.addrs) |addr| {
|
for (addrList.addrs) |addr| {
|
||||||
const ping = net.tcpConnectToAddress(addr) catch {
|
//const ping = net.tcpConnectToAddress(addr) catch {
|
||||||
continue;
|
// continue;
|
||||||
};
|
//};
|
||||||
|
|
||||||
ping.close();
|
//ping.close();
|
||||||
final_addr = addr;
|
final_addr = addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ pub const HttpService = struct {
|
||||||
|
|
||||||
pub fn startMessenger(self: *HttpService, connections: []ServiceConnection, tickets: []ServiceTicket, thread_id: usize) void {
|
pub fn startMessenger(self: *HttpService, connections: []ServiceConnection, tickets: []ServiceTicket, thread_id: usize) void {
|
||||||
while (true) {
|
while (true) {
|
||||||
Thread.sleep(1_000_000);
|
Thread.sleep(5_000_000);
|
||||||
if (self.thread_stop[thread_id]) {
|
if (self.thread_stop[thread_id]) {
|
||||||
var conn_open = false;
|
var conn_open = false;
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ pub const HttpService = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn updateHealth(self: *HttpService, thread_id: usize) void {
|
fn updateHealth(self: *HttpService, thread_id: usize) void {
|
||||||
while (true) {
|
while (false) {
|
||||||
if (self.thread_stop[thread_id]) {
|
if (self.thread_stop[thread_id]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -302,9 +302,10 @@ pub const HttpService = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn updateCapacity(self: *HttpService, thread_id: usize) void {
|
fn updateCapacity(self: *HttpService, thread_id: usize) void {
|
||||||
while (true) {
|
while (false) {
|
||||||
Thread.sleep(1_000_000);
|
Thread.sleep(500_000_000);
|
||||||
var count: usize = 0;
|
var count: usize = 0;
|
||||||
|
|
||||||
for (self.connections) |conn| {
|
for (self.connections) |conn| {
|
||||||
if (conn.status == .ocuppied) {
|
if (conn.status == .ocuppied) {
|
||||||
count += 1;
|
count += 1;
|
||||||
|
|
Loading…
Reference in a new issue