Skip to content

Commit 152c717

Browse files
Merge pull request #2571 from DougAnsonAustinTX/django_LP_review
Django LP tech review: updates for django LP tech review
2 parents 727d66f + 44b3a89 commit 152c717

File tree

13 files changed

+145
-93
lines changed

13 files changed

+145
-93
lines changed

content/learning-paths/servers-and-cloud-computing/django-on-gcp/_index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
---
22
title: Deploy Django on Google Cloud C4A (Arm-based Axion VMs)
33

4+
draft: true
5+
cascade:
6+
draft: true
7+
48
minutes_to_complete: 30
59

610
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.

content/learning-paths/servers-and-cloud-computing/django-on-gcp/baseline.md

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Django Baseline Testing on Google Axion C4A Arm Virtual Machine
3-
weight: 5
3+
weight: 6
44

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

16-
#### Activate your Python environment
17-
Before running Django, activate the Python virtual environment you created during installation.
18-
19-
```console
20-
source venv/bin/activate
21-
```
22-
2316
#### Create a new Django project
2417
Run the following command to create a new Django project named `myproject`:
2518

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

4841
```console
49-
python manage.py migrate
42+
python3 manage.py migrate
5043
```
5144

45+
You should get output showing the Running Migrations (all of which should be "OK").
46+
5247
#### Start the Django development server
5348
Before starting the Django development server, you must configure your ALLOWED_HOSTS setting to allow access from your VM’s external IP.
5449
This ensures that Django accepts HTTP requests from outside the localhost (e.g., when testing in a browser or from another machine).
@@ -59,14 +54,14 @@ This ensures that Django accepts HTTP requests from outside the localhost (e.g.,
5954
Move into your Django project directory where the settings.py file is located.
6055

6156
```console
62-
cd ~/myproject/mysite/mysite
57+
cd ~/myproject/myproject/
6358
```
6459

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

6863
```console
69-
vi settings.py
64+
edit myproject/settings.py
7065
```
7166

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

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

9085
```python
9186
ALLOWED_HOSTS = ['your-external-ip', 'your-domain.com']
9287
```
9388

94-
#### Enable Port 8000 in GCP Firewall
95-
96-
By default, Google Cloud VMs block external traffic on custom ports like 8000. You must open this port to access Django from your browser.
97-
9889
**Now start the Django development server:**
9990

91+
We can now start the Django development server since we have exposed TCP/8000 in our VM via firewall rules:
10092
```console
101-
python manage.py runserver 0.0.0.0:8000
93+
python3 manage.py runserver 0.0.0.0:8000
10294
```
10395

10496
#### View in browser
105-
Open a web browser on your local machine (Chrome, Firefox, Edge, etc.) and enter the following URL in the address bar:
97+
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:
10698

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

125117
```console
126-
python manage.py startapp hello
118+
python3 manage.py startapp hello
127119
```
128120

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

152144
#### Create app URL configuration
153-
Create a new file hello/urls.py and add:
145+
Create a new file `hello/urls.py` and add:
154146

155147
```python
156148
from django.urls import path
@@ -210,7 +202,7 @@ INSTALLED_APPS = [
210202
#### Run the server again
211203

212204
```console
213-
python manage.py runserver 0.0.0.0:8000
205+
python3 manage.py runserver 0.0.0.0:8000
214206
```
215207

216208
#### Test your app

content/learning-paths/servers-and-cloud-computing/django-on-gcp/benchmarking.md

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Django Benchmarking
3-
weight: 6
3+
weight: 7
44

55
### FIXED, DO NOT MODIFY
66
layout: learningpathall
@@ -11,6 +11,9 @@ layout: learningpathall
1111
This section describes how to benchmark a Django web application deployed with **Gunicorn** using **ApacheBench (ab)** — a lightweight HTTP benchmarking tool.
1212
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.
1313

14+
### Stop the server
15+
Press `Ctrl + C` to stop the Django server if running.
16+
1417
### Ensure ApacheBench is installed
1518
**ApacheBench (ab)** is a command-line tool used to benchmark web servers by simulating multiple HTTP requests.
1619

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

30-
### Activate Django Virtual Environment
31-
A virtual environment isolates Python dependencies for your Django project to prevent version conflicts.
32-
33-
```console
34-
cd ~/myproject
35-
source venv/bin/activate
36-
```
37-
When activated, your shell prompt should show (`venv`) — indicating you’re inside the virtual environment.
38-
3933
**Ensure Django and Gunicorn are installed:**
4034

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

47-
### Run Django Migrations and Collect Static Files
48-
Before running the server, initialize the database and prepare static files.
49-
50-
```console
51-
python manage.py migrate
52-
python manage.py collectstatic --noinput
53-
```
54-
- `migrate` applies database schema changes (like creating tables).
55-
- `collectstatic` gathers static assets (CSS, JS, images) into a single directory for efficient serving.
56-
57-
This ensures your Django project is fully configured and ready for deployment under Gunicorn.
58-
5941
### Run Django with Gunicorn
60-
Use Gunicorn to serve your Django application for benchmarking:
42+
Use Gunicorn to serve your Django application for benchmarking (run in the background):
6143

6244
```console
63-
gunicorn myproject.wsgi:application --bind 0.0.0.0:8000 --workers 4
45+
gunicorn myproject.wsgi:application --bind 0.0.0.0:8000 --workers 4 &
6446
```
6547

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

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

123+
### Cleanup
124+
125+
With the following output (above) seen, you can type "fg" followed by "ctrl-c" to exit the gunicorn server that is running.
126+
141127
### Benchmark Metrics Explanation
142128

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

154-
### Benchmark summary on x86_64
155-
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:
156-
157-
| **Parameter** | **Description** | **Value** |
158-
|----------------|------------------|-----------|
159-
| **Server Software** | Web server used for serving Django | gunicorn |
160-
| **Server Hostname** | Host address tested | 127.0.0.1 |
161-
| **Server Port** | Port number for benchmark | 8000 |
162-
| **Document Path** | Endpoint used for testing | / |
163-
| **Document Length** | Size of each response | 12068 bytes |
164-
| **Concurrency Level** | Number of concurrent requests | 10 |
165-
| **Time Taken for Tests** | Total time to complete all requests | 0.364 seconds |
166-
| **Complete Requests** | Total number of successful requests | 1000 |
167-
| **Failed Requests** | Number of failed requests | 0 |
168-
| **Total Transferred** | Total bytes transferred (including headers) | 12,351,000 bytes |
169-
| **HTML Transferred** | Total HTML body bytes transferred | 12,068,000 bytes |
170-
| **Requests per Second (mean)** | Throughput — higher is better | **2750.72 req/sec** |
171-
| **Time per Request (mean)** | Average time for each request | **3.635 ms** |
172-
| **Time per Request (across all concurrent requests)** | Average latency considering concurrency | **0.364 ms** |
173-
| **Transfer Rate** | Network throughput rate | **33,177.89 KB/sec** |
174-
175-
### Benchmark summary on Arm64
140+
### Benchmark summary
176141
Results from the earlier run on the `c4a-standard-4` (4 vCPU, 16 GB memory) Arm64 VM in GCP (SUSE):
177142

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

196-
### Django benchmarking comparison on Arm64 and x86_64
197-
198161
- **Exceptional Throughput:** The Arm64 VM efficiently handled nearly 10K requests per second, showcasing excellent concurrency handling.
199162
- **Low Latency:** Average response time stayed around 1 ms, indicating rapid request processing even under load.
200163
- **High Efficiency:** Zero failed requests demonstrate stable and reliable performance under benchmark conditions.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: Create a Firewall Rule on GCP
3+
weight: 3
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Overview
10+
11+
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.
12+
13+
{{% notice Note %}}
14+
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/).
15+
{{% /notice %}}
16+
17+
## Create a Firewall Rule in GCP
18+
19+
For this learning path, we need to expose TCP port 8000. To accomplish this, we first need to create a firewall rule.
20+
- Navigate to the [Google Cloud Console](https://console.cloud.google.com/).
21+
- Go to **VPC Network > Firewall** and press **Create firewall rule**.
22+
23+
![Create a firewall rule](images/firewall-rule.png "Create a firewall rule")
24+
25+
- Next, we create the firewall rule that will expose TCP port 8000 for our learning path.
26+
- Set the "Name" of the new rule to "allow-tcp-8000"
27+
- 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)
28+
- Direction of traffic should be set to "Ingress"
29+
- Allow on match should be set to "Allow" and the "Targets" should be set to "Specified target tags".
30+
- Enter "allow-tcp-8000" to the "Target tags" text field
31+
- Set the "Source IPv4 ranges" text value to "0.0.0.0/0"
32+
33+
![Create a firewall rule](images/network-rule.png "Creating the TCP/8000 firewall rule")
34+
35+
- Lastly, we select "Specified protocols and ports" under the "Protocols and ports" section
36+
- Select the "TCP" checkbox
37+
- Enter "8000" in the "Ports" text field
38+
- Press "Create"
39+
40+
![Specifying the TCP port to expose](images/network-port.png "Specifying the TCP port to expose")
41+
42+
Our network firewall rule is now created so we can continue with the VM creation!
75.2 KB
Loading
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: Create a Firewall Rule on GCP
3+
weight: 3
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Overview
10+
11+
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.
12+
13+
{{% notice Note %}}
14+
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/).
15+
{{% /notice %}}
16+
17+
## Create a Firewall Rule in GCP
18+
19+
For this learning path, we need to expose TCP port 8000. To accomplish this, we first need to create a firewall rule.
20+
- Navigate to the [Google Cloud Console](https://console.cloud.google.com/).
21+
- Go to **VPC Network > Firewall** and press **Create firewall rule**.
22+
23+
![Create a firewall rule](images/firewall-rule.png "Create a firewall rule")
24+
25+
- Next, we create the firewall rule that will expose TCP port 8000 for our learning path.
26+
- Set the "Name" of the new rule to "allow-tcp-8000"
27+
- 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)
28+
- Direction of traffic should be set to "Ingress"
29+
- Allow on match should be set to "Allow" and the "Targets" should be set to "Specified target tags".
30+
- Enter "allow-tcp-8000" to the "Target tags" text field
31+
- Set the "Source IPv4 ranges" text value to "0.0.0.0/0"
32+
33+
![Create a firewall rule](images/network-rule.png "Creating the TCP/8000 firewall rule")
34+
35+
- Lastly, we select "Specified protocols and ports" under the "Protocols and ports" section
36+
- Select the "TCP" checkbox
37+
- Enter "8091" in the "Ports" text field
38+
- Press "Create"
39+
40+
![Specifying the TCP port to expose](images/network-port.png "Specifying the TCP port to expose")
41+
42+
Our network firewall rule is now created so we can continue with the VM creation!
23.5 KB
Loading
22.3 KB
Loading
138 KB
Loading
79.6 KB
Loading

0 commit comments

Comments
 (0)