Good afternoon.
I have rented a VPS server and my website is running on it.
To increase the bandwidth, I decided to move to a more powerful server. (the characteristics are shown below)
The old server:
-
CPU: 4 core
-
RAM: 6GB
-
HDD: 165 GB
The new server:
-
CPU: 12 core
-
RAM: 24 GB
-
HDD: 295 GB
But as a result, I got that everything works 5 times slower on the new server.
Performed profiling on both servers using xdebug.
As a result of the analysis of the results, it turned out that the md5 function works in 2 ms on the old server, and in 10 ms on the new server.
Since this function is used in the process of localization of the site text into other languages, this feature slows down the loading of all countries by ~ 5 times
Below is the function in which the md5 function is called:
function __($key = ''){
if(get_session('language')){
$language = get_session('language');
}else{
if(!get_user("language")){
$code = get_user("language");
$language = db_get("*", TB_LANGUAGE_CATEGORY, ["code" => $code]);
if(empty($language)){
$language = db_get("*", TB_LANGUAGE_CATEGORY, ["is_default" => 1]);
}
}else{
$language = db_get("*", TB_LANGUAGE_CATEGORY, ["is_default" => 1]);
}
$language = json_encode($language);
if(!empty($language)){
set_session(["language" => $language]);
}
}
if($language){
$language = is_string($language)?json_decode( $language ):$language;
if(isset($language->code)){
$lang_file = WRITEPATH."lang/".$language->code.".json";
if(file_exists($lang_file)){
$data = file_get_contents(WRITEPATH."lang/".$language->code.".json");
$data = json_decode($data, 1);
if(isset($data['data'])){
$data = $data['data'];
if($key != "" && isset($data[ md5($key) ])){
return $data[ md5($key) ];
}
}
}
}
}
return $key;
}
The old server:
The new server:
QUESTION: The crux of the question is why the function runs 5 times slower on the new server (in 10 ms, versus 2 ms on the old server)
addition: The results in 2ms and 10ms are only for 1 function call. And there are more than 50 such calls when loading a page, which ultimately leads to a delay of 5 seconds for the user.