1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
cluster.php
См. документацию.
1<?php
3
5{
6 public static function Add($arFields)
7 {
8 global $DB;
9 $ID = $DB->Add('b_perf_cluster', $arFields);
10 return $ID;
11 }
12
13 public static function Truncate()
14 {
15 global $DB;
16 $res = $DB->Query('DELETE FROM b_perf_cluster');
17 return $res;
18 }
19
27 public static function GetList($arOrder = false, $arFilter = false, $arSelect = false)
28 {
29 global $DB;
30
31 if (!is_array($arSelect))
32 {
33 $arSelect = [];
34 }
35 if (count($arSelect) < 1)
36 {
37 $arSelect = [
38 'ID',
39 'TIMESTAMP_X',
40 'THREADS',
41 'HITS',
42 'ERRORS',
43 'PAGES_PER_SECOND',
44 'PAGE_EXEC_TIME',
45 'PAGE_RESP_TIME',
46 ];
47 }
48
49 if (!is_array($arOrder))
50 {
51 $arOrder = [];
52 }
53
54 $arQueryOrder = [];
55 foreach ($arOrder as $strColumn => $strDirection)
56 {
57 $strColumn = mb_strtoupper($strColumn);
58 $strDirection = mb_strtoupper($strDirection) === 'ASC' ? 'ASC' : 'DESC';
59 if ($strColumn === 'ID')
60 {
61 $arSelect[] = $strColumn;
62 $arQueryOrder[$strColumn] = $strColumn . ' ' . $strDirection;
63 }
64 }
65
66 $arQuerySelect = [];
67 foreach ($arSelect as $strColumn)
68 {
69 $strColumn = mb_strtoupper($strColumn);
70 switch ($strColumn)
71 {
72 case 'ID':
73 case 'TIMESTAMP_X':
74 case 'THREADS':
75 case 'HITS':
76 case 'ERRORS':
77 case 'PAGES_PER_SECOND':
78 case 'PAGE_EXEC_TIME':
79 case 'PAGE_RESP_TIME':
80 $arQuerySelect[$strColumn] = 'p.' . $strColumn;
81 break;
82 }
83 }
84 if (count($arQuerySelect) < 1)
85 {
86 $arQuerySelect = ['ID' => 'p.ID'];
87 }
88
89 $obQueryWhere = new CSQLWhere;
90 $arFields = [
91 'ID' => [
92 'TABLE_ALIAS' => 'p',
93 'FIELD_NAME' => 'p.ID',
94 'FIELD_TYPE' => 'int',
95 'JOIN' => false,
96 ],
97 ];
98 $obQueryWhere->SetFields($arFields);
99
100 if (!is_array($arFilter))
101 {
102 $arFilter = [];
103 }
104 $strQueryWhere = $obQueryWhere->GetQuery($arFilter);
105
106 $bDistinct = $obQueryWhere->bDistinctReqired;
107
108 $strSql = '
109 SELECT ' . ($bDistinct ? 'DISTINCT' : '') . '
110 ' . implode(', ', $arQuerySelect) . '
111 FROM
112 b_perf_cluster p
113 ' . $obQueryWhere->GetJoins() . '
114 ';
115
116 if ($strQueryWhere)
117 {
118 $strSql .= '
119 WHERE
120 ' . $strQueryWhere . '
121 ';
122 }
123
124 if (count($arQueryOrder) > 0)
125 {
126 $strSql .= '
127 ORDER BY
128 ' . implode(', ', $arQueryOrder) . '
129 ';
130 }
131
132 return $DB->Query($strSql, false, '', ['fixed_connection' => true]);
133 }
134
135 public function Measure($host, $port, $url, $threads, $iterations = 3, $arOptions = [])
136 {
137 global $DB;
138
139 $strRequest = 'GET ' . $url . " HTTP/1.0\r\n";
140 $strRequest .= "User-Agent: BitrixSMCluster (thread #thread#)\r\n";
141 $strRequest .= "Accept: */*\r\n";
142 $strRequest .= 'Host: ' . $host . "\r\n";
143 $strRequest .= "Accept-Language: en\r\n";
144
145 $socket_timeout = intval($arOptions['socket_timeout'] ?? 0);
146 if ($socket_timeout <= 0)
147 {
148 $socket_timeout = 20;
149 }
150
151 $rw_timeout = intval($arOptions['rw_timeout'] ?? 0);
152 if ($rw_timeout <= 0)
153 {
154 $rw_timeout = 20;
155 }
156
157 $iteration_timeout = intval($arOptions['iteration_timeout'] ?? 0);
158 if ($iteration_timeout <= 0)
159 {
160 $iteration_timeout = 30;
161 }
162
163 if ($port == 443)
164 {
165 $proto = 'ssl://';
166 }
167 else
168 {
169 $proto = '';
170 }
171
172 $start = microtime(1);
173 $end = $start + $iterations;
174 $end_after_end = $start + $iteration_timeout;
175
176 $errors = 0;
177 $arConnections = [];
178 $arCookie = [];
179 $arStartTimes = [];
180 $Pages = 0;
181 $arPageExecTime = [];
182 $arResponseTime = [];
183 while (microtime(1) < $end)
184 {
185 //Open new connection if needed
186 if (count($arConnections) < $threads)
187 {
188 //Find first free slot
189 for ($j = 0; $j < $threads; $j++)
190 {
191 if (!isset($arConnections[$j]))
192 {
193 $arStartTimes[$j] = microtime(1);
194 $socket = fsockopen($proto . $host, $port, $errno, $errstr, $socket_timeout);
195 if ($socket)
196 {
197 $request = str_replace('#thread#', $j, $strRequest);
198 if (isset($arCookie[$j]))
199 {
200 $request .= 'Cookie: ' . implode(';', $arCookie[$j]) . "\r\n";
201 }
202 $request .= "\r\n";
203
204 stream_set_blocking($socket, true);
205 stream_set_timeout($socket, $rw_timeout);
206 fputs($socket, $request);
207 stream_set_blocking($socket, false);
208 $arConnections[$j] = $socket;
209 $Pages++;
210 }
211 else
212 {
213 $arConnections[$j] = false;
214 $errors++;
215 }
216 break;
217 }
218 }
219 }
220
221 //Try to read connections
222 foreach ($arConnections as $j => $socket)
223 {
224 if ($socket)
225 {
226 if (feof($socket))
227 {
228 $arResponseTime[] = microtime(1) - $arStartTimes[$j];
229 fclose($socket);
230 unset($arConnections[$j]);
231 }
232 else
233 {
234 $line = fgets($socket);
235 if ($line !== false)
236 {
237 if (preg_match('/^Set-Cookie: (.*?)=(.*?);/', $line, $match))
238 {
239 $arCookie[$j][$match[1]] = $match[1] . '=' . $match[2];
240 }
241 elseif (preg_match('/<span id="bx_main_exec_time">(\\d+\\.\\d+)<\\/span>/', $line, $match))
242 {
243 $arPageExecTime[] = $match[1];
244 }
245 elseif (preg_match('/^HTTP\\/\\d+\\.\\d+\\s+(\\d+)\\s/', $line, $match))
246 {
247 if ($match[1] !== '200')
248 {
249 $errors++;
250 }
251 }
252 elseif (preg_match('/^Status:\\s+(\\d+)\\s/', $line, $match))
253 {
254 if ($match[1] !== '200')
255 {
256 $errors++;
257 }
258 }
259 }
260 }
261 }
262 }
263 }
264
265 //Finish all connections
266 while (count($arConnections) > 0)
267 {
268 //Try to read connections
269 foreach ($arConnections as $j => $socket)
270 {
271 if ($socket)
272 {
273 if (feof($socket))
274 {
275 $arResponseTime[] = microtime(1) - $arStartTimes[$j];
276 fclose($socket);
277 unset($arConnections[$j]);
278 }
279 else
280 {
281 $line = fgets($socket);
282 if ($line !== false)
283 {
284 if (preg_match('/<span id="bx_main_exec_time">(\\d+\\.\\d+)<\\/span>/', $line, $match))
285 {
286 $arPageExecTime[] = $match[1];
287 }
288 elseif (preg_match('/^HTTP\\/\\d+\\.\\d+\\s+(\\d+)\\s/', $line, $match))
289 {
290 if ($match[1] !== '200')
291 {
292 $errors++;
293 }
294 }
295 elseif (preg_match('/^Status:\\s+(\\d+)\\s/', $line, $match))
296 {
297 if ($match[1] !== '200')
298 {
299 $errors++;
300 }
301 }
302 }
303 }
304 }
305 else
306 {
307 unset($arConnections[$j]);
308 }
309 if (microtime(1) > $end_after_end)
310 {
311 break;
312 }
313 }
314 if (microtime(1) > $end_after_end)
315 {
316 break;
317 }
318 }
319
320 static::Add([
321 '~TIMESTAMP_X' => $DB->CurrentTimeFunction(),
322 'THREADS' => $threads,
323 'HITS' => $Pages,
324 'ERRORS' => $errors,
325 'PAGES_PER_SECOND' => $Pages / $iterations,
326 'PAGE_EXEC_TIME' => count($arPageExecTime) ? array_sum($arPageExecTime) / count($arPageExecTime) : 0,
327 'PAGE_RESP_TIME' => count($arResponseTime) ? array_sum($arResponseTime) / count($arResponseTime) : 0,
328 ]);
329 }
330}
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
Определения cluster.php:5
static Add($arFields)
Определения cluster.php:6
static Truncate()
Определения cluster.php:13
static GetList($arOrder=false, $arFilter=false, $arSelect=false)
Определения cluster.php:27
Measure($host, $port, $url, $threads, $iterations=3, $arOptions=[])
Определения cluster.php:135
Определения sqlwhere.php:1359
$arFields
Определения dblapprove.php:5
$res
Определения filter_act.php:7
$start
Определения get_search.php:9
if($ajaxMode) $ID
Определения get_user.php:27
$host
Определения .description.php:9
$errors
Определения iblock_catalog_edit.php:74
global $DB
Определения cron_frame.php:29
$arOptions
Определения structure.php:223
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$arFilter
Определения user_search.php:106
$url
Определения iframe.php:7