Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

website not function properly in autoscaling

Hi

I am running a webserver using compute engine with cloud SQL. I set up a stateless MIG with image i preinstalled the apache etc. i set the autoscaling min 1 and max 5. when it in normal condition (1 VM) the website running ok and no error. when it start to autoscale to 2 VM and above. The website intermittently fetch data from the Cloud SQL, and give error the page requested not found.

Does anybody know why? and can help to assist.

Thank you for your time 

Solved Solved
3 2 160
1 ACCEPTED SOLUTION

Hello @lompat31  ,Welcome on Google Cloud Community.

1. Did you've checked LoadBalancers' healthcheck ? When you've spinning additional VM in MIG, does it have healthy status ? 
2. How your website is connecting with CloudSQL? I have 3tier app with simple PHP app and CloudSQL instance and MIGs. My connection file looks as follow

php file

<?php include "../inc/dbinfo.inc"; ?> 

/* Connect to MySQL and select the database. */
  $connection = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD);
  if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error();
  $database = mysqli_select_db($connection, DB_DATABASE);

dbinfo.inc

cat <<'EOF' >> /var/www/inc/dbinfo.inc
<?php
define('DB_SERVER', '${sql_endpoint}');
define('DB_USERNAME', '${sql_user}');
define('DB_PASSWORD', '${sql_password}');
define('DB_DATABASE', '${sql_name}');
?>
EOF

I'm installing also LAMP stack, and serve my site as site.php , behind loadbalancer. 

Basically it looks like either something is wrong with your LB or with connection between php client ( website) and SQL. 
--
cheers,
DamianS
LinkedIn medium.com Cloudskillsboost

View solution in original post

2 REPLIES 2

Hello @lompat31  ,Welcome on Google Cloud Community.

1. Did you've checked LoadBalancers' healthcheck ? When you've spinning additional VM in MIG, does it have healthy status ? 
2. How your website is connecting with CloudSQL? I have 3tier app with simple PHP app and CloudSQL instance and MIGs. My connection file looks as follow

php file

<?php include "../inc/dbinfo.inc"; ?> 

/* Connect to MySQL and select the database. */
  $connection = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD);
  if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error();
  $database = mysqli_select_db($connection, DB_DATABASE);

dbinfo.inc

cat <<'EOF' >> /var/www/inc/dbinfo.inc
<?php
define('DB_SERVER', '${sql_endpoint}');
define('DB_USERNAME', '${sql_user}');
define('DB_PASSWORD', '${sql_password}');
define('DB_DATABASE', '${sql_name}');
?>
EOF

I'm installing also LAMP stack, and serve my site as site.php , behind loadbalancer. 

Basically it looks like either something is wrong with your LB or with connection between php client ( website) and SQL. 
--
cheers,
DamianS
LinkedIn medium.com Cloudskillsboost

Thanks @DamianS , it was the Loadbalancer, I set the session affinity as Client IP.