Hello, I want to create hundreds of static routes in a VPC to the internet gateway.
My problem is that each route takes around 7 seconds to be created.
- routes.insert takes less than a second,
- most of the time is spent in operation.wait
I have tried batched requests. It saves I/O but it does some save much time.
AWS and Azure are order of magnitude faster than GCP for this use case.
What would you suggest to be able to create a big route table in a timely manner?
Thank you,
Hi @Prime541 ,
GCP's API is designed to be idempotent, meaning that it ensures that the desired state is always reached, even if the request is sent multiple times. Its drawback is longer wait times when making changes to a VPC's routing configuration.
You can speed it up by using a different approach. nstead of using the routes.insert
method to create individual routes, you can use a Cloud Deployment Manager (CDM) template to define the entire routing configuration in a single YAML file. You can check my sample CDM template below:
resources:
- name: my-vpc
type: compute.v1.network
properties:
name: my-vpc
autoCreateSubnetworks: false
routingConfig:
routingMode: REGIONAL
routes:
- name: route-1
destRange: 10.0.0.0/24
nextHopIp: 10.0.0.1
- name: route-2
destRange: 10.0.1.0/24
nextHopIp: 10.0.1.1
# Add more routes here
To deploy this template, you can use the gcloud deployment-manager deployments create
command. This command will create the VPC with the specified routing configuration in a single API call, which should be significantly faster than creating the routes individually.
Let me know if it helps.
Is there an API call that can be used via the library instead of relying on `gcloud` external tool?
I think this is the API documentation for deployment-manager https://cloud.google.com/deployment-manager/docs/deployments#api? I guess the call would be like this, but I'm not sure how much faster as while the api call will return quickly, you'll have to poll for the results with https://cloud.google.com/deployment-manager/docs/reference/latest/operations/get:
POST https://www.googleapis.com/deploymentmanager/v2/projects/myproject/global/deployments
{
"name": "example-config-with-templates",
"target": {
"config": {
"content": "resources:\n- name: vm-created-by-cloud-config\n type: compute.v1.instance\n properties:\n zone: us-central1-a\n machineType: https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1\n disks:\n - deviceName: boot\n type: PERSISTENT\n boot: true\n autoDelete: true\n initializeParams:\n diskName: disk-created-by-cloud-config\n sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20151104\n networkInterfaces:\n - network: https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default\n"
}
}
}