1. Customize the compute resource of the Mage web service
Mage web serivce is responsbile for running Mage web backend, scheduler service and local block executions. You can customize the CPU and memory of the Mage web service by updating the Terraform variables and then runningterraform apply
- AWS: Update the
ecs_task_cpuandecs_task_memoryvariables in themage-ai-terraform-templates/aws/variables.tffile. - GCP: Update the
container_cpuandcontainer_memoryvariables in themage-ai-terraform-templates/gcp/variables.tffile.
2. Set executor type and customize the compute resource of the Mage executor
Mage provides multiple executors to execute blocks. Here are the available executor types:- Block executor
local_pythonecsgcp_cloud_runazure_container_instancek8s
- Pipeline executor
local_pythonecsk8s
local_python executor type by default. If you want to specify another executor_type as the default executor type for blocks,
you can set the environment variable DEFAULT_EXECUTOR_TYPE to one executor type mentioned above.
If you want to use local_python executor when DEFAULT_EXECUTOR_TYPE is set to another executor type, you can set the executor_type to
local_python_force.
Local python executor
Local python exeuctors are running within the same container of Mage scheduler service. You can customize the compute resource with the same way mentioned in the Customize the compute resource of the Mage web service section.Kubernetes executor
If your Mage app is running in a Kubernetes cluster, you can execute the blocks in separate Kubernetes pods with Kubernetes executor. To configure a pipeline block to use Kubernetes executor, you simply just need to update theexecutor_type of the block to k8s in pipeline’s metadata.yaml:
default as the Kubernetes namespace. You can customize the namespace by setting the KUBE_NAMESPACE environment variable.
There’re three ways to customize the Kubernetes executor config:
- Add the
executor_configat block level in pipeline’s metadata.yaml file. Example config: - Add the
k8s_executor_configto project’s metadata.yaml. Thisk8s_executor_configwill apply to all the blocks that use k8s executor in this project. Example config:
- The kubernetes job name is in this format:
mage-{job_name_prefix}-block-{block_run_id}. The defaultjob_name_prefixisdata-prep. You can customize it in the k8s executor config. - If you want to use GPU resource in your k8s executor, you can configure the GPU resource in the
k8s_executor_configlikePlease make sure the GPU driver is installed and run on your nodes to use the GPUs. - To futher customize the container config of the kubernetes executor, you can sepcify the
container_configin the k8s executor config. Here is the example:
- You can configure the job template by using the
K8S_CONFIG_FILEenvironment variable, which should point to the configuration file. Here is the format for the Kubernetes configuration template:
MAGE_CONTAINER_NAME. If this variable is not set, Mage will default to using the first container in the pod. To specify the Mage container, you can use:
AWS ECS executor
You can choose to launch separate AWS ECS tasks to executor blocks by specifying block executor_type to beecs in pipeline’s metadata.yaml file.
There’re 2 ways to customize the compute resource of ECS executor,
- Update
cpuandmemorytheecs_configin project’s metadata.yaml file. Example config: - Add the
executor_configat block level in pipeline’s metadata.yaml file. Example config:
executor_type at pipeline level and set run_pipeline_in_one_process to true.
executor_config can also be set at pipeline level. Here is the example pipeline metadata.yaml:
Extra fields
| Field name | Description | Example values |
|---|---|---|
| assign_public_ip | Whether to assign public IP to the ECS task. | true/false (default: true) |
| enable_execute_command | Whether to enable execute command for debugging | true/false (default: false) |
| wait_timeout | The maximum wait time for the ECS task (in seoncds). The default wait timeout for the ECS task is 10 minutes. | 1200 (default: 600) |
GCP Cloud Run executor
If your Mage app is deployed on GCP, you can choose to launch separate GCP Cloud Run jobs to execute blocks. How to configure pipeline to use GCP cloud run executor:- Update Project’s metadata.yaml
- Update the
executor_typeof block togcp_cloud_runin pipeline’s metadata.yaml:
Azure Container Instance executor
If your Mage app is deployed on Microsoft Azure with Mage’s terraform scripts, you can choose to launch separate Azure containce instances to execute blocks. How to configure pipeline to use Azure Container Instance executor:- Update Project’s metadata.yaml
- Update the
executor_typeof the block toazure_container_instancein pipeline’s metadata.yaml and specifyexecutor_configoptionally. The block level executor_config will override the global executor_config.
PySpark executor
If the pipeline type is “pyspark”, we use PySpark exeuctors for pipeline and block executions. You can customize the compute resource of PySpark exeuctor by updating the instance types ofemr_config in project’s metadata.yaml file.
Example config: