Debian Codegraph @

docs/concurrency/concurrency.html

raw
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <title>Multi-threading Performance</title>
7 <script src="https://cdn.tailwindcss.com"></script>
8 <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js"></script>
9 <style>
10 body {
11 font-family: 'Inter', sans-serif;
12 background-color: #f3f4f6;
13 }
14 canvas {
15 background-color: #ffffff;
16 border-radius: 0.75rem;
17 padding: 1.5rem;
18 box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
19 }
20 </style>
21 </head>
22 <body class="p-6 md:p-12 flex items-center justify-center min-h-screen">
23 <div class="w-full max-w-4xl mx-auto space-y-8">
24 <!-- Card container with rounded corners and shadow -->
25 <div class="bg-white p-8 rounded-xl shadow-lg">
26 <h1 class="text-3xl font-bold text-gray-900 text-center mb-2">
27 Task Performance vs. Concurrency
28 </h1>
29 <p class="text-gray-600 text-center mb-6">
30 Line chart showing the breakdown of task completion time for each metric, including the performance gain.
31 </p>
32
33 <!-- Chart container -->
34 <div>
35 <canvas id="performanceChart"></canvas>
36 </div>
37 </div>
38
39 <!-- Data source and analysis section -->
40 <div class="bg-white p-6 rounded-xl shadow-lg text-gray-700">
41 <h2 class="text-xl font-semibold mb-2">Data Analysis</h2>
42 <p class="mb-4">
43 The data was extracted from the provided `multi-threading.txt` file. The system's CPU has 6 physical cores but 12 logical CPUs, thanks to Hyper-Threading technology.
44 </p>
45 <p class="mb-4">
46 As the number of concurrent processes increases from 1 to 6, the task completion time decreases significantly as each process gets a dedicated physical core. The performance gain continues between 6 and 9 processes because the system starts using the second logical thread on each core, utilizing idle resources to improve efficiency.
47 </p>
48 <p>
49 Beyond 12 concurrent processes, the performance gains diminish, and the time can even slightly increase. This is likely due to the overhead of the operating system needing to manage and switch between more processes than there are logical cores.
50 </p>
51 </div>
52
53 <!-- New section for explaining the metrics -->
54 <div class="bg-white p-6 rounded-xl shadow-lg text-gray-700">
55 <h2 class="text-xl font-semibold mb-2">Understanding the Time Metrics</h2>
56 <ul class="list-disc list-inside space-y-2">
57 <li>
58 <strong>Real Time:</strong> This is the total elapsed time from start to finish, including time spent waiting for other processes or I/O. It's the "wall-clock" time you would measure with a stopwatch.
59 </li>
60 <li>
61 <strong>User Time:</strong> This is the amount of time the CPU spent executing the user's code. It reflects the time spent on the actual computations of your program.
62 </li>
63 <li>
64 <strong>System Time:</strong> This is the amount of time the CPU spent on system-level tasks on behalf of your program, such as interacting with the operating system kernel, handling I/O, or managing memory.
65 </li>
66 </ul>
67 <p class="mt-4">
68 In a multi-threaded application, the sum of user time and system time can be greater than the real time because multiple cores are working in parallel.
69 </p>
70 </div>
71 </div>
72
73 <script>
74 document.addEventListener('DOMContentLoaded', () => {
75 const ctx = document.getElementById('performanceChart').getContext('2d');
76
77 // Data extracted and converted from the uploaded file.
78 const realTimeData = [135.894, 83.660, 73.339, 59.056, 53.401, 50.978, 52.683, 50.230, 52.204];
79 const userTimeData = [28.587, 28.489, 33.579, 32.258, 31.836, 31.978, 33.811, 33.574, 32.865];
80 const systemTimeData = [21.053, 21.773, 29.538, 25.384, 23.953, 24.865, 25.185, 24.492, 25.004];
81
82 const baselineRealTime = realTimeData[0];
83 const performanceGainData = realTimeData.map(time => baselineRealTime / time);
84
85 const data = {
86 labels: [1, 2, 5, 6, 9, 12, 18, 24, 48],
87 datasets: [
88 {
89 label: 'Real Time',
90 data: realTimeData,
91 yAxisID: 'yTime',
92 backgroundColor: 'rgba(59, 130, 246, 0.6)',
93 borderColor: 'rgba(59, 130, 246, 1)',
94 borderWidth: 2,
95 pointBackgroundColor: 'rgba(29, 78, 216, 1)',
96 pointBorderColor: '#ffffff',
97 pointRadius: 6,
98 pointHoverRadius: 8,
99 tension: 0.3,
100 fill: false
101 },
102 {
103 label: 'User Time',
104 data: userTimeData,
105 yAxisID: 'yTime',
106 backgroundColor: 'rgba(16, 185, 129, 0.6)',
107 borderColor: 'rgba(16, 185, 129, 1)',
108 borderWidth: 2,
109 pointBackgroundColor: 'rgba(5, 150, 105, 1)',
110 pointBorderColor: '#ffffff',
111 pointRadius: 6,
112 pointHoverRadius: 8,
113 tension: 0.3,
114 fill: false
115 },
116 {
117 label: 'System Time',
118 data: systemTimeData,
119 yAxisID: 'yTime',
120 backgroundColor: 'rgba(249, 115, 22, 0.6)',
121 borderColor: 'rgba(249, 115, 22, 1)',
122 borderWidth: 2,
123 pointBackgroundColor: 'rgba(234, 88, 12, 1)',
124 pointBorderColor: '#ffffff',
125 pointRadius: 6,
126 pointHoverRadius: 8,
127 tension: 0.3,
128 fill: false
129 },
130 {
131 label: 'Performance Gain',
132 data: performanceGainData,
133 yAxisID: 'yGain',
134 backgroundColor: 'rgba(139, 92, 246, 0.6)',
135 borderColor: 'rgba(139, 92, 246, 1)',
136 borderWidth: 2,
137 pointBackgroundColor: 'rgba(109, 40, 217, 1)',
138 pointBorderColor: '#ffffff',
139 pointRadius: 6,
140 pointHoverRadius: 8,
141 tension: 0.3,
142 fill: false
143 }
144 ]
145 };
146
147 // Chart configuration
148 const config = {
149 type: 'line',
150 data: data,
151 options: {
152 responsive: true,
153 maintainAspectRatio: false,
154 scales: {
155 x: {
156 title: {
157 display: true,
158 text: 'Number of Concurrent Processes',
159 font: {
160 size: 16,
161 weight: 'bold'
162 },
163 color: '#4b5563'
164 },
165 ticks: {
166 color: '#6b7280'
167 }
168 },
169 yTime: {
170 type: 'linear',
171 position: 'left',
172 beginAtZero: true,
173 title: {
174 display: true,
175 text: 'Time (seconds)',
176 font: {
177 size: 16,
178 weight: 'bold'
179 },
180 color: '#4b5563'
181 },
182 ticks: {
183 color: '#6b7280'
184 }
185 },
186 yGain: {
187 type: 'linear',
188 position: 'right',
189 beginAtZero: true,
190 grid: {
191 drawOnChartArea: false, // only want the grid lines for the left axis
192 },
193 title: {
194 display: true,
195 text: 'Performance Gain (x)',
196 font: {
197 size: 16,
198 weight: 'bold'
199 },
200 color: '#4b5563'
201 },
202 ticks: {
203 color: '#6b7280'
204 }
205 }
206 },
207 plugins: {
208 legend: {
209 display: true,
210 position: 'top',
211 labels: {
212 color: '#1f2937'
213 }
214 },
215 tooltip: {
216 mode: 'index',
217 intersect: false,
218 callbacks: {
219 label: function(context) {
220 let label = context.dataset.label || '';
221 if (label) {
222 label += ': ';
223 }
224 if (context.parsed.y !== null) {
225 if (context.dataset.label === 'Performance Gain') {
226 label += context.parsed.y.toFixed(2) + 'x';
227 } else {
228 label += context.parsed.y.toFixed(3) + 's';
229 }
230 }
231 return label;
232 }
233 }
234 }
235 }
236 }
237 };
238
239 // Create the chart
240 new Chart(ctx, config);
241 });
242 </script>
243 </body>
244 </html>
245