-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_server.py
More file actions
116 lines (87 loc) · 3.58 KB
/
Copy pathmulti_server.py
File metadata and controls
116 lines (87 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python3
"""
Multi-Server Example
This example demonstrates a multi-server queueing system
and compares performance with different numbers of servers.
"""
import pdq
def analyze_multiserver(servers, users, think_time, service_time):
"""Analyze a multi-server system with given parameters"""
model_name = f"MultiServer_{servers}_servers"
model = pdq.PDQModel(model_name)
# Create multi-server node (MSC for closed networks)
model.create_closed("Users", pdq.TERM, users, think_time)
model.create_multinode(servers, "CPUPool", pdq.MSC, pdq.FCFS)
model.set_demand("CPUPool", "Users", service_time)
# Solve using exact method for closed networks
model.solve(pdq.EXACT)
# Get metrics
response_time = model.get_response(pdq.TERM, "Users")
throughput = model.get_throughput(pdq.TERM, "Users")
utilization = model.get_utilization("CPUPool", "Users", pdq.TERM)
return {
'servers': servers,
'response_time': response_time,
'throughput': throughput,
'utilization': utilization,
'utilization_pct': utilization * 100
}
def main():
"""Run multi-server comparison example"""
print("=== Multi-Server Comparison Example ===\\n")
# Model parameters
users = 20
think_time = 5.0 # seconds
service_time = 2.0 # seconds per request
print(f"Model Parameters:")
print(f" Users: {users}")
print(f" Think time: {think_time} sec")
print(f" Service time: {service_time} sec")
print()
# Compare different numbers of servers
server_counts = [1, 2, 3, 4, 5]
results = []
print("Analyzing different server configurations...")
print()
for servers in server_counts:
result = analyze_multiserver(servers, users, think_time, service_time)
results.append(result)
print(f"Servers: {servers}")
print(f" Response time: {result['response_time']:.3f} sec")
print(f" Throughput: {result['throughput']:.3f} req/sec")
print(f" Per-server utilization: {result['utilization_pct']:.1f}%")
print()
# Show comparison table
print("=== Performance Comparison ===")
print("Servers | Response Time | Throughput | Utilization")
print("--------|---------------|------------|------------")
for result in results:
print(f"{result['servers']:7d} | "
f"{result['response_time']:11.3f}s | "
f"{result['throughput']:8.3f}/s | "
f"{result['utilization_pct']:9.1f}%")
print()
# Calculate improvement ratios
base_response = results[0]['response_time']
base_throughput = results[0]['throughput']
print("=== Improvement over Single Server ===")
print("Servers | Response Ratio | Throughput Ratio")
print("--------|----------------|------------------")
for result in results:
response_ratio = base_response / result['response_time']
throughput_ratio = result['throughput'] / base_throughput
print(f"{result['servers']:7d} | "
f"{response_ratio:12.2f}x | "
f"{throughput_ratio:14.2f}x")
print()
# Show detailed report for optimal configuration
print("=== Detailed Report for 3-Server Configuration ===")
model = pdq.PDQModel("Optimal MultiServer")
model.set_comment("Multi-server system with optimal configuration")
model.create_closed("Users", pdq.TERM, users, think_time)
model.create_multinode(3, "CPUPool", pdq.MSC, pdq.FCFS)
model.set_demand("CPUPool", "Users", service_time)
model.solve(pdq.EXACT)
model.print_report()
if __name__ == "__main__":
main()