Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---
title: Deploy Django on Google Cloud C4A (Arm-based Axion VMs)

draft: true
cascade:
draft: true

minutes_to_complete: 30

who_is_this_for: This learning path is intended for software developers deploying and optimizing Django-based web applications on Linux/Arm64 environments, specifically using Google Cloud C4A virtual machines powered by Axion processors.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Django Baseline Testing on Google Axion C4A Arm Virtual Machine
weight: 5
weight: 6

### FIXED, DO NOT MODIFY
layout: learningpathall
Expand All @@ -13,13 +13,6 @@ You will first run the Django development server and access it from your browser
### Baseline 1 — View Django Welcome Page
This test confirms that Django is installed correctly and the server runs successfully.

#### Activate your Python environment
Before running Django, activate the Python virtual environment you created during installation.

```console
source venv/bin/activate
```

#### Create a new Django project
Run the following command to create a new Django project named `myproject`:

Expand All @@ -46,9 +39,11 @@ myproject/
Migrations prepare your project’s database by creating the required tables for Django’s internal apps (admin, authentication, etc.):

```console
python manage.py migrate
python3 manage.py migrate
```

You should get output showing the Running Migrations (all of which should be "OK").

#### Start the Django development server
Before starting the Django development server, you must configure your ALLOWED_HOSTS setting to allow access from your VM’s external IP.
This ensures that Django accepts HTTP requests from outside the localhost (e.g., when testing in a browser or from another machine).
Expand All @@ -59,14 +54,14 @@ This ensures that Django accepts HTTP requests from outside the localhost (e.g.,
Move into your Django project directory where the settings.py file is located.

```console
cd ~/myproject/mysite/mysite
cd ~/myproject/myproject/
```

- Open settings.py File
Use any text editor (like vi or nano) to open the file.
Use any text editor (like vi or nano) to open the file ("edit" is used as an example below).

```console
vi settings.py
edit myproject/settings.py
```

- Locate the `ALLOWED_HOSTS` Line
Expand All @@ -79,30 +74,27 @@ This ensures that Django accepts HTTP requests from outside the localhost (e.g.,

- Allow All Hosts (for Testing Only)
To make your Django app accessible from your VM’s external IP address, update it to:
```pthon
```python
ALLOWED_HOSTS = ['*']
```
{{% notice Note %}}
Allowing all hosts `('*')` is suitable **only for development or testing**.
For production, replace `'*'` with specific domain names or IPs, such as:
For production, replace `'*'` with specific domain names or IPs, such as your public IP address for your VM that you recorded earlier:
{{% /notice %}}

```python
ALLOWED_HOSTS = ['your-external-ip', 'your-domain.com']
```

#### Enable Port 8000 in GCP Firewall

By default, Google Cloud VMs block external traffic on custom ports like 8000. You must open this port to access Django from your browser.

**Now start the Django development server:**

We can now start the Django development server since we have exposed TCP/8000 in our VM via firewall rules:
```console
python manage.py runserver 0.0.0.0:8000
python3 manage.py runserver 0.0.0.0:8000
```

#### View in browser
Open a web browser on your local machine (Chrome, Firefox, Edge, etc.) and enter the following URL in the address bar:
Open a web browser on your local machine (Chrome, Firefox, Edge, etc.) and enter the following URL in the address bar. Please replace "YOUR_VM_EXTERNAL_IP" with the external IP address of your VM that you saved off earlier:

```console
http://<YOUR_VM_EXTERNAL_IP>:8000
Expand All @@ -123,7 +115,7 @@ Press `Ctrl + C` to stop the Django server if running.
Within your Django project directory, create a new app named `hello`:

```console
python manage.py startapp hello
python3 manage.py startapp hello
```

**This creates the following directory:**
Expand All @@ -150,7 +142,7 @@ def home(request):
This defines a simple view function that sends a basic HTML message as the HTTP response.

#### Create app URL configuration
Create a new file hello/urls.py and add:
Create a new file `hello/urls.py` and add:

```python
from django.urls import path
Expand Down Expand Up @@ -210,7 +202,7 @@ INSTALLED_APPS = [
#### Run the server again

```console
python manage.py runserver 0.0.0.0:8000
python3 manage.py runserver 0.0.0.0:8000
```

#### Test your app
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Django Benchmarking
weight: 6
weight: 7

### FIXED, DO NOT MODIFY
layout: learningpathall
Expand All @@ -11,6 +11,9 @@ layout: learningpathall
This section describes how to benchmark a Django web application deployed with **Gunicorn** using **ApacheBench (ab)** — a lightweight HTTP benchmarking tool.
You will measure **throughput (requests per second)** and **latency (response time)** to evaluate the performance of your Django app on an Arm-based GCP SUSE VM.

### Stop the server
Press `Ctrl + C` to stop the Django server if running.

### Ensure ApacheBench is installed
**ApacheBench (ab)** is a command-line tool used to benchmark web servers by simulating multiple HTTP requests.

Expand All @@ -27,45 +30,24 @@ This confirms ApacheBench is correctly installed and available system-wide.
ab -V
```

### Activate Django Virtual Environment
A virtual environment isolates Python dependencies for your Django project to prevent version conflicts.

```console
cd ~/myproject
source venv/bin/activate
```
When activated, your shell prompt should show (`venv`) — indicating you’re inside the virtual environment.

**Ensure Django and Gunicorn are installed:**

```console
pip install django gunicorn
python3 -m pip install django gunicorn
```
- **Django** is the Python web framework you’re benchmarking.
- **Gunicorn** is a high-performance WSGI HTTP server for deploying Django apps in production-like environments.

### Run Django Migrations and Collect Static Files
Before running the server, initialize the database and prepare static files.

```console
python manage.py migrate
python manage.py collectstatic --noinput
```
- `migrate` applies database schema changes (like creating tables).
- `collectstatic` gathers static assets (CSS, JS, images) into a single directory for efficient serving.

This ensures your Django project is fully configured and ready for deployment under Gunicorn.

### Run Django with Gunicorn
Use Gunicorn to serve your Django application for benchmarking:
Use Gunicorn to serve your Django application for benchmarking (run in the background):

```console
gunicorn myproject.wsgi:application --bind 0.0.0.0:8000 --workers 4
gunicorn myproject.wsgi:application --bind 0.0.0.0:8000 --workers 4 &
```

- `--workers 4`: number of worker processes
- `--bind 0.0.0.0:8000`: binds to all interfaces on port 8000
- Replace `myproject.wsgi:application` with your actual Django project name.
- `myproject.wsgi:application` your Django project name ("myproject" used in this example).

{{% notice Note %}}
Keep this terminal running during the benchmark. If you’re testing remotely, ensure port 8000 is open in your VM firewall settings.
Expand Down Expand Up @@ -138,6 +120,10 @@ Percentage of the requests served within a certain time (ms)
100% 5 (longest request)
```

### Cleanup

With the following output (above) seen, you can type "fg" followed by "ctrl-c" to exit the gunicorn server that is running.

### Benchmark Metrics Explanation

- **Concurrency Level:** Number of requests executed simultaneously during the test.
Expand All @@ -151,28 +137,7 @@ Percentage of the requests served within a certain time (ms)
- **Time per Request (across concurrent):** Mean time per request across all concurrent clients.
- **Transfer Rate:** Average network data throughput during the benchmark.

### Benchmark summary on x86_64
To compare the benchmark results, the following results were collected by running the same benchmark on a `x86 - c4-standard-4` (4 vCPUs, 15 GB Memory) x86_64 VM in GCP, running SUSE:

| **Parameter** | **Description** | **Value** |
|----------------|------------------|-----------|
| **Server Software** | Web server used for serving Django | gunicorn |
| **Server Hostname** | Host address tested | 127.0.0.1 |
| **Server Port** | Port number for benchmark | 8000 |
| **Document Path** | Endpoint used for testing | / |
| **Document Length** | Size of each response | 12068 bytes |
| **Concurrency Level** | Number of concurrent requests | 10 |
| **Time Taken for Tests** | Total time to complete all requests | 0.364 seconds |
| **Complete Requests** | Total number of successful requests | 1000 |
| **Failed Requests** | Number of failed requests | 0 |
| **Total Transferred** | Total bytes transferred (including headers) | 12,351,000 bytes |
| **HTML Transferred** | Total HTML body bytes transferred | 12,068,000 bytes |
| **Requests per Second (mean)** | Throughput — higher is better | **2750.72 req/sec** |
| **Time per Request (mean)** | Average time for each request | **3.635 ms** |
| **Time per Request (across all concurrent requests)** | Average latency considering concurrency | **0.364 ms** |
| **Transfer Rate** | Network throughput rate | **33,177.89 KB/sec** |

### Benchmark summary on Arm64
### Benchmark summary
Results from the earlier run on the `c4a-standard-4` (4 vCPU, 16 GB memory) Arm64 VM in GCP (SUSE):

| **Parameter** | **Description** | **Value** |
Expand All @@ -193,8 +158,6 @@ Results from the earlier run on the `c4a-standard-4` (4 vCPU, 16 GB memory) Arm6
| **Time per Request (across all concurrent requests)** | Average latency considering concurrency | **0.104 ms** |
| **Transfer Rate** | Network throughput rate | **2639.00 KB/sec** |

### Django benchmarking comparison on Arm64 and x86_64

- **Exceptional Throughput:** The Arm64 VM efficiently handled nearly 10K requests per second, showcasing excellent concurrency handling.
- **Low Latency:** Average response time stayed around 1 ms, indicating rapid request processing even under load.
- **High Efficiency:** Zero failed requests demonstrate stable and reliable performance under benchmark conditions.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: Create a Firewall Rule on GCP
weight: 3

### FIXED, DO NOT MODIFY
layout: learningpathall
---

## Overview

In this section, you will learn how to create a Firewall Rule within Google Cloud Console. For this learning path, we need to expose TCP port 8000.

{{% notice Note %}}
For support on GCP setup, see the Learning Path [Getting started with Google Cloud Platform](https://learn.arm.com/learning-paths/servers-and-cloud-computing/csp/google/).
{{% /notice %}}

## Create a Firewall Rule in GCP

For this learning path, we need to expose TCP port 8000. To accomplish this, we first need to create a firewall rule.
- Navigate to the [Google Cloud Console](https://console.cloud.google.com/).
- Go to **VPC Network > Firewall** and press **Create firewall rule**.

![Create a firewall rule](images/firewall-rule.png "Create a firewall rule")

- Next, we create the firewall rule that will expose TCP port 8000 for our learning path.
- Set the "Name" of the new rule to "allow-tcp-8000"
- Select your network that you intend to bind to your VM (default is "autoscaling-net" but your organization might have others that you need to use)
- Direction of traffic should be set to "Ingress"
- Allow on match should be set to "Allow" and the "Targets" should be set to "Specified target tags".
- Enter "allow-tcp-8000" to the "Target tags" text field
- Set the "Source IPv4 ranges" text value to "0.0.0.0/0"

![Create a firewall rule](images/network-rule.png "Creating the TCP/8000 firewall rule")

- Lastly, we select "Specified protocols and ports" under the "Protocols and ports" section
- Select the "TCP" checkbox
- Enter "8000" in the "Ports" text field
- Press "Create"

![Specifying the TCP port to expose](images/network-port.png "Specifying the TCP port to expose")

Our network firewall rule is now created so we can continue with the VM creation!
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: Create a Firewall Rule on GCP
weight: 3

### FIXED, DO NOT MODIFY
layout: learningpathall
---

## Overview

In this section, you will learn how to create a Firewall Rule within Google Cloud Console. For this learning path, we need to expose TCP port 8000.

{{% notice Note %}}
For support on GCP setup, see the Learning Path [Getting started with Google Cloud Platform](https://learn.arm.com/learning-paths/servers-and-cloud-computing/csp/google/).
{{% /notice %}}

## Create a Firewall Rule in GCP

For this learning path, we need to expose TCP port 8000. To accomplish this, we first need to create a firewall rule.
- Navigate to the [Google Cloud Console](https://console.cloud.google.com/).
- Go to **VPC Network > Firewall** and press **Create firewall rule**.

![Create a firewall rule](images/firewall-rule.png "Create a firewall rule")

- Next, we create the firewall rule that will expose TCP port 8000 for our learning path.
- Set the "Name" of the new rule to "allow-tcp-8000"
- Select your network that you intend to bind to your VM (default is "autoscaling-net" but your organization might have others that you need to use)
- Direction of traffic should be set to "Ingress"
- Allow on match should be set to "Allow" and the "Targets" should be set to "Specified target tags".
- Enter "allow-tcp-8000" to the "Target tags" text field
- Set the "Source IPv4 ranges" text value to "0.0.0.0/0"

![Create a firewall rule](images/network-rule.png "Creating the TCP/8000 firewall rule")

- Lastly, we select "Specified protocols and ports" under the "Protocols and ports" section
- Select the "TCP" checkbox
- Enter "8091" in the "Ports" text field
- Press "Create"

![Specifying the TCP port to expose](images/network-port.png "Specifying the TCP port to expose")

Our network firewall rule is now created so we can continue with the VM creation!
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading