diff --git a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/_index.md b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/_index.md index 04e201628..4c1ce1bcd 100644 --- a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/_index.md +++ b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/_index.md @@ -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. diff --git a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/baseline.md b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/baseline.md index d4efc7367..955ce42de 100644 --- a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/baseline.md +++ b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/baseline.md @@ -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 @@ -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`: @@ -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). @@ -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 @@ -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://:8000 @@ -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:** @@ -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 @@ -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 diff --git a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/benchmarking.md b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/benchmarking.md index 28325cb90..230ecad86 100644 --- a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/benchmarking.md +++ b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/benchmarking.md @@ -1,6 +1,6 @@ --- title: Django Benchmarking -weight: 6 +weight: 7 ### FIXED, DO NOT MODIFY layout: learningpathall @@ -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. @@ -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. @@ -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. @@ -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** | @@ -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. diff --git a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/firewall_setup.md b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/firewall_setup.md new file mode 100644 index 000000000..983fcdb15 --- /dev/null +++ b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/firewall_setup.md @@ -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! \ No newline at end of file diff --git a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/firewall-rule.png b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/firewall-rule.png new file mode 100644 index 000000000..cb2d9bf40 Binary files /dev/null and b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/firewall-rule.png differ diff --git a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/firewall_setup.md b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/firewall_setup.md new file mode 100644 index 000000000..1322281f0 --- /dev/null +++ b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/firewall_setup.md @@ -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! \ No newline at end of file diff --git a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/gcp-pubip-ssh.png b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/gcp-pubip-ssh.png new file mode 100644 index 000000000..558745de3 Binary files /dev/null and b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/gcp-pubip-ssh.png differ diff --git a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/gcp-shell.png b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/gcp-shell.png new file mode 100644 index 000000000..7e2fc3d1b Binary files /dev/null and b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/gcp-shell.png differ diff --git a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/network-config.png b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/network-config.png new file mode 100644 index 000000000..007340eaf Binary files /dev/null and b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/network-config.png differ diff --git a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/network-port.png b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/network-port.png new file mode 100644 index 000000000..49e43f057 Binary files /dev/null and b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/network-port.png differ diff --git a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/network-rule.png b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/network-rule.png new file mode 100644 index 000000000..9a073d4df Binary files /dev/null and b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/images/network-rule.png differ diff --git a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/installation.md b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/installation.md index 808da5da4..1271b33f9 100644 --- a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/installation.md +++ b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/installation.md @@ -1,6 +1,6 @@ --- title: Install Django -weight: 4 +weight: 5 ### FIXED, DO NOT MODIFY layout: learningpathall @@ -21,29 +21,20 @@ sudo zypper update -y **Django** requires **Python 3.10+**. We will use Python 3.11, which is compatible with Django 5. You will also install `pip` for package management, and basic developer tools (`git`, `gcc`, and `make`) to build Python packages and work with Django projects. ```console -sudo zypper install -y python311 python311-pip python311-devel +sudo zypper install -y python311 python311-pip python311-devel sudo zypper install -y git gcc make ``` -**Use Python 3.11 as the Default (optional):** - -If multiple Python versions exist on your system, you can set Python 3.11 as your default Python 3 interpreter using **update-alternatives**. - -```console -sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 -sudo update-alternatives --config python3 -``` - **Ensure that both Python and pip are installed correctly:** ```console -python3 --version +python3.11 --version pip3 --version ``` You should see an output similar to: ```output -Python 3.11.13 +Python 3.11.10 pip 22.3.1 from /usr/lib/python3.11/site-packages/pip (python 3.11) ``` @@ -52,10 +43,10 @@ It’s recommended to create a dedicated project directory and use a **virtual e ```console mkdir ~/myproject && cd ~/myproject -python3 -m venv venv +python3.11 -m venv venv source venv/bin/activate ``` -- `python3 -m venv venv` — creates a virtual environment named venv inside your project folder. +- `python3.11 -m venv venv` — creates a virtual environment named venv inside your project folder. - `source venv/bin/activate` — activates the virtual environment. Once activated, your command prompt will show (venv) at the beginning, indicating that you’re working inside an isolated Python environment. @@ -63,8 +54,8 @@ Once activated, your command prompt will show (venv) at the beginning, indicatin With your virtual environment active, upgrade pip and install Django using the following commands: ```console -pip3 install --upgrade pip -pip3 install django +python3 -m pip install --upgrade pip +python3 -m pip install django ``` **Confirm that Django is installed correctly by checking its version:** @@ -75,6 +66,6 @@ django-admin --version You should see an output similar to: ```output -5.2.7 +5.2.8 ``` Django is installed successfully and ready for project setup. diff --git a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/instance.md b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/instance.md index 2b93bc950..3291e8d4b 100644 --- a/content/learning-paths/servers-and-cloud-computing/django-on-gcp/instance.md +++ b/content/learning-paths/servers-and-cloud-computing/django-on-gcp/instance.md @@ -1,6 +1,6 @@ --- title: Create a Google Axion C4A Arm virtual machine on GCP -weight: 3 +weight: 4 ### FIXED, DO NOT MODIFY layout: learningpathall @@ -26,6 +26,24 @@ To create a virtual machine based on the C4A instance type: ![Create a Google Axion C4A Arm virtual machine in the Google Cloud Console with c4a-standard-4 selected alt-text#center](images/gcp-vm.png "Creating a Google Axion C4A Arm virtual machine in Google Cloud Console") -- Under **OS and Storage**, select **Change**, then choose an Arm64-based OS image. For this Learning Path, use **SUSE Linux Enterprise Server**. Pick the preferred version for your Operating System. Ensure you select the **Arm image** variant. Click **Select**. + +- Under **OS and Storage**, select **Change**, then choose an Arm64-based OS image. For this Learning Path, use **SUSE Linux Enterprise Server**. +- If using use **SUSE Linux Enterprise Server**. Select "Pay As You Go" for the license type. +- Once appropriately selected, please Click **Select**. - Under **Networking**, enable **Allow HTTP traffic**. +- Also under **Networking**, in the "Network tags" text field add "allow-tcp-8000" as an additional tag + +![Adding the TCP/8000 firewall rule to our VM](images/network-config.png "Adding the TCP/8000 firewall rule to our VM") + - Click **Create** to launch the instance. +- Once created, you should see a "SSH" option to the right in your list of VM instances. You should also see the public IP address for your VM. +- Save off the public IP address for your VM as you will need this in the next step. +- Click on this to launch a SSH shell into your VM instance: + +![Invoke a SSH session via your browser alt-text#center](images/gcp-pubip-ssh.png "Invoke a SSH session into your running VM instance") + +- A window from your browser should come up and you should now see a shell into your VM instance: + +![Terminal Shell in your VM instance alt-text#center](images/gcp-shell.png "Terminal shell in your VM instance") + +Next, let's install Couchbase! \ No newline at end of file