## Module 4: Use Burstable Feature

  ![40%](https://lab-static.pingcap.com/quick-demo/demo-006-3-en.png)

### Step 1. Turn On BURSTABLE To Serve Both Workloads With The Best Effort

+ On [Terminal 1](ssh://monitor1-ssh#1), review and run the script to set up resource groups for `userA` and `userB` with low quotas on RU per seconds but burstable. The script gives `userA` a higher priority than `userB`.

  ```bash
  cat lab3-rc-setup.sh
  ```

  ```output
  #!/bin/bash

  source ./hosts-env.sh

  # For cluster
  export MYSQL_PS1="tidb:db1> "
  mysql -h ${HOST_DB1_PRIVATE_IP} -P 4000 -u root --verbose << 'EOFX'
  ALTER USER userA RESOURCE GROUP default;
  ALTER USER userB RESOURCE GROUP default;
  DROP RESOURCE GROUP IF EXISTS rg1;
  DROP RESOURCE GROUP IF EXISTS rg2;
  CREATE RESOURCE GROUP rg1 RU_PER_SEC=500 PRIORITY=HIGH BURSTABLE;
  CREATE RESOURCE GROUP rg2 RU_PER_SEC=500 PRIORITY=MEDIUM BURSTABLE;
  ALTER USER userA RESOURCE GROUP rg1;
  ALTER USER userB RESOURCE GROUP rg2;
  SELECT * FROM information_schema.resource_groups;
  SELECT Host,user, User_attributes FROM mysql.user WHERE user IN ('userA','userB');
  EOFX
  ```

  ```bash
  ./lab3-rc-setup.sh
  ```

  ```output
  ...
  --------------
  SELECT * FROM information_schema.resource_groups
  --------------

  NAME	RU_PER_SEC	PRIORITY	BURSTABLE	QUERY_LIMIT	BACKGROUND
  default	UNLIMITED	MEDIUM	YES	NULL	NULL
  rg1	500	HIGH	YES	NULL	NULL
  rg2	500	MEDIUM	YES	NULL	NULL
  --------------
  SELECT Host,user, User_attributes FROM mysql.user WHERE user IN ('userA','userB')
  --------------

  Host	user	User_attributes
  %	userA	{"resource_group": "rg1"}
  %	userB	{"resource_group": "rg2"}
  ```

### Step 2. Start the workloads

+ On [Terminal 1](ssh://monitor1-ssh#1), run the script to start a batch workload by `userA` (no output), keep the script running.

  ```bash
  ./lab3-workload-userA.sh
  ```

+ On [Terminal 2](ssh://monitor1-ssh#2), run the script to start the same batch workload by `userB` (no output), keep the script running.

   ```bash
   ./lab3-workload-userB.sh
   ```

### Step 3. Observe the result

+ Wait for 1 minute, log in to the [Grafana Prometheus Dashboard](http://${LAB:HOST_MONITOR1_PUBLIC_IP}:3000), find `tidb-demo-TiDB-Resource-Control` -> `Resource Details` -> `KV CPU Time`. Because of the `BURSTABLE` setting, the difference in `CPU Time` between them is not as obvious as in Module 3.

  ![60%](https://lab-static.pingcap.com/quick-demo/demo-006-M4-burstable-grafana-v2-20250331.png)

+ Press <kbd>Ctrl</kbd>+<kbd>C</kbd> to stop both workloads before proceeding to the next module.
