이 문서에서는 압축 배치 정책을 지정하여 작업의 VM 간에 네트워크 지연 시간을 줄이는 방법을 설명합니다.
영역 내에서 VM 호스트를 서로 물리적으로 더 가깝게 배치하면 VM 간의 네트워크 지연 시간을 줄일 수 있습니다. 이러한 성능상의 이점은 MPI 라이브러리를 사용하여 통신하는 작업과 같이 긴밀하게 결합된 태스크가 있는 작업에 특히 유용합니다.
작업을 만들 때 원하는 경우 압축 배치 정책을 지정하여 작업의 VM이 서로 더 가까이 위치하도록 요구할 수 있습니다.
그렇지 않으면 기본 VM 배치는 일반적으로 전원 장애의 영향을 최소화하기 위해 별도의 호스트에 VM을 분산합니다.
압축 배치 정책에 관한 자세한 내용은 Compute Engine 문서의 배치 정책 정보를 참고하세요.
작업에 압축 배치 정책을 사용하도록 지정하면 Batch가 작업의 VM에 관한 압축 배치 정책을 자동으로 만들고 삭제합니다. 작업에 기존 압축 배치 정책을 지정할 수 없습니다.
압축 배치 정책의 VM 수는 지정할 수 없습니다.
작업의 압축 배치 정책은 작업이 실행되는 VM 수와 관계없이 적용됩니다.
배치 정책을 사용하는 작업 만들기 및 실행
gcloud CLI 또는 Batch API를 사용하여 collocation 필드를 COLLOCATED로 설정하여 작업에 압축 배치 정책을 사용하도록 지정할 수 있습니다.
gcloud
작업의 구성 세부정보를 지정하고 collocation 필드를 COLLOCATED로 설정하는 JSON 파일을 만드세요.
예를 들어 압축 배치 정책을 지정하는 기본 스크립트 작업을 만들려면 다음 콘텐츠가 포함된 JSON 파일을 만듭니다.
{"taskGroups":[{"taskSpec":{"runnables":[{"script":{"text":"echo Hello world from task ${BATCH_TASK_INDEX}"}}]},"taskCount":3}],"allocationPolicy":{"placement":{"collocation":"COLLOCATED"}},"logsPolicy":{"destination":"CLOUD_LOGGING"}}
JSON_CONFIGURATION_FILE: 작업의 구성 세부정보가 포함된 JSON 파일의 경로
API
collocation 필드를 COLLOCATED로 설정하는 jobs.create 메서드에 대해 POST 요청을 실행합니다.
예를 들어 압축 배치 정책을 지정하는 기본 스크립트 작업을 만들려면 다음 요청을 실행합니다.
POSThttps://batch.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/jobs?job_id=JOB_NAME{"taskGroups":[{"taskSpec":{"runnables":[{"script":{"text":"echo Hello world from task ${BATCH_TASK_INDEX}"}}]},"taskCount":3}],"allocationPolicy":{"placement":{"collocation":"COLLOCATED"}},"logsPolicy":{"destination":"CLOUD_LOGGING"}}
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-02-11(UTC)"],[[["\u003cp\u003eSpecifying a compact placement policy reduces network latency between a job's virtual machines (VMs) by ensuring they are located on physically closer hosts within a zone.\u003c/p\u003e\n"],["\u003cp\u003eCompact placement policies are beneficial for jobs with tightly coupled tasks, especially those that utilize MPI libraries for communication.\u003c/p\u003e\n"],["\u003cp\u003eBatch automatically creates and manages compact placement policies when specified, without the ability to use a pre-existing one or specifying the number of VMs.\u003c/p\u003e\n"],["\u003cp\u003eYou can set a compact placement policy for a job by setting the \u003ccode\u003ecollocation\u003c/code\u003e field to \u003ccode\u003eCOLLOCATED\u003c/code\u003e in the job configuration, either through the gcloud CLI or the Batch API.\u003c/p\u003e\n"],["\u003cp\u003eBefore creating a job, ensure you have the necessary permissions, which includes the Batch Job Editor role and the Service Account User role.\u003c/p\u003e\n"]]],[],null,["# Reduce latency by using compact placement policies\n\nThis document explains how to reduce network latency among a job's VMs by\nspecifying a compact placement policy.\n\nHaving VM hosts that are physically closer to each other within a\n[zone](/compute/docs/regions-zones#zones_and_clusters) can reduce\nnetwork latency between VMs. This performance benefit can be especially useful\nfor jobs with tightly coupled tasks, such as\n[tasks that communicate using MPI libraries](/batch/docs/create-run-job-mpi-library).\nWhen you create a job, you can optionally require a job's VMs to be located\ncloser to each other by specifying a compact placement policy.\nOtherwise, default VM placement typically distributes VMs across\nseparate hosts to help minimize the impact of power failures.\n\nTo learn more about compact placement policies, see\n[About placement policies](/compute/docs/instances/placement-policies-overview)\nin the Compute Engine documentation.\n\nBefore you begin\n----------------\n\n1. If you haven't used Batch before, review [Get started with Batch](/batch/docs/get-started) and enable Batch by completing the [prerequisites for projects and users](/batch/docs/get-started#prerequisites).\n2.\n\n To get the permissions that\n you need to create a job,\n\n ask your administrator to grant you the\n following IAM roles:\n\n - [Batch Job Editor](/iam/docs/roles-permissions/batch#batch.jobsEditor) (`roles/batch.jobsEditor`) on the project\n - [Service Account User](/iam/docs/roles-permissions/iam#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`) on the [job's service account](/batch/docs/create-run-job-custom-service-account#create-job-service-account), which by default is the [default Compute Engine service account](/compute/docs/access/service-accounts#default_service_account)\n\n\n For more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\n You might also be able to get\n the required permissions through [custom\n roles](/iam/docs/creating-custom-roles) or other [predefined\n roles](/iam/docs/roles-overview#predefined).\n\n\u003cbr /\u003e\n\nRestrictions\n------------\n\nIn addition to the\n[general restrictions for compact placement policies](/compute/docs/instances/placement-policies-overview#restrictions-compact-policies),\nBatch also has the following restrictions:\n\n- When you specify for a job to use a compact placement policy, Batch automatically creates and deletes a compact placement policy for the job's VMs. You can't specify an existing compact placement policy for a job.\n- You can't specify a number of VMs for the compact placement policy. The compact placement policy for a job applies regardless of how many VMs the job runs on.\n\nCreate and run a job that uses a placement policy\n-------------------------------------------------\n\nYou can specify for a job to use a compact placement policy by setting the\n[`collocation` field](/batch/docs/reference/rest/v1/projects.locations.jobs#PlacementPolicy.FIELDS.collocation)\nto `COLLOCATED` using the gcloud CLI or Batch API. \n\n### gcloud\n\n1. Create a JSON file that specifies the job's configuration details and sets\n the `collocation` field to `COLLOCATED`.\n\n For example, to create a basic script job that specifies a\n compact placement policy, create a JSON file with the following contents: \n\n {\n \"taskGroups\": [\n {\n \"taskSpec\": {\n \"runnables\": [\n {\n \"script\": {\n \"text\": \"echo Hello world from task ${BATCH_TASK_INDEX}\"\n }\n }\n ]\n },\n \"taskCount\": 3\n }\n ],\n \"allocationPolicy\": {\n \"placement\": {\n \"collocation\": \"COLLOCATED\"\n }\n },\n \"logsPolicy\": {\n \"destination\": \"CLOUD_LOGGING\"\n }\n }\n\n2. To create and run the job, use the\n [`gcloud batch jobs submit` command](/sdk/gcloud/reference/batch/jobs/submit):\n\n gcloud batch jobs submit \u003cvar translate=\"no\"\u003eJOB_NAME\u003c/var\u003e \\\n --location \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e \\\n --config \u003cvar translate=\"no\"\u003eJSON_CONFIGURATION_FILE\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eJOB_NAME\u003c/var\u003e: the name of the job.\n\n - \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: the [location](/batch/docs/locations)\n of the job.\n\n - \u003cvar translate=\"no\"\u003eJSON_CONFIGURATION_FILE\u003c/var\u003e: the path for a JSON\n file with the job's configuration details.\n\n### API\n\nMake a `POST` request to the\n[`jobs.create` method](/batch/docs/reference/rest/v1/projects.locations.jobs/create)\nthat sets the `collocation` field to `COLLOCATED`.\n\nFor example, to create a basic script job that specifies a\ncompact placement policy, make the following request: \n\n POST https://batch.googleapis.com/v1/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e/jobs?job_id=\u003cvar translate=\"no\"\u003eJOB_NAME\u003c/var\u003e\n\n {\n \"taskGroups\": [\n {\n \"taskSpec\": {\n \"runnables\": [\n {\n \"script\": {\n \"text\": \"echo Hello world from task ${BATCH_TASK_INDEX}\"\n }\n }\n ]\n },\n \"taskCount\": 3\n }\n ],\n \"allocationPolicy\": {\n \"placement\": {\n \"collocation\": \"COLLOCATED\"\n }\n },\n \"logsPolicy\": {\n \"destination\": \"CLOUD_LOGGING\"\n }\n }\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the\n [project ID](/resource-manager/docs/creating-managing-projects#identifying_projects)\n of your project.\n\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: the [location](/batch/docs/locations)\n of the job.\n\n- \u003cvar translate=\"no\"\u003eJOB_NAME\u003c/var\u003e: the name of the job.\n\nWhat's next\n-----------\n\n- If you have issues creating or running a job, see [Troubleshooting](/batch/docs/troubleshooting).\n- [View jobs and tasks](/batch/docs/view-jobs-tasks).\n- Learn about more [job creation options](/batch/docs/create-run-job#job-creation-options)."]]