日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

本文解釋了您的疑問:您有一個 Python 程序 test.py,在本地環(huán)境您可以 python test.py,但是在批量計算上應(yīng)該如何運行呢?

test.py 內(nèi)容如下:

print('Hello, cloud!')

批量計算上運行任務(wù)大致過程為:

  1. 您提交作業(yè)到批量計算,批量計算會按照您提供的配置去申請?zhí)摂M機資源。

  2. 批量計算啟動虛擬機,并在虛擬機中運行 python test.py,得到結(jié)果后自動上傳到 OSS 中。

  3. 您前往 OSS 查看運行結(jié)果。

1. 提交作業(yè)的方法有很多,下面列舉幾種

1.1. 使用命令行

運行命令:

bcs sub "python test.py" -p ./test.py
  • 這條命令會將 test.py 文件打包成 worker.tar.gz 上傳到指定位置,然后再提交作業(yè)運行。

  • bcs命令需要先安裝 batchcompute-cli 工具才能使用, 請看準備工作

  • bcs sub命令:

bcs sub <commandLine> [job_name] [options]

更多參數(shù)詳情可以通過 bcs sub -h 查看。

1.2. 使用控制臺

下面列舉詳細解釋步驟。

1.2.1. 將 test.py 打包上傳到 OSS

在 test.py 所在目錄運行下面的命令:

tar -czf worker.tar.gz test.py # 將 test.py 打包到 worker.tar.gz

然后使用OSS控制臺將 worker.tar.gz 上傳到 OSS。

說明

如果還沒有開通 OSS,請先開通. 還需要創(chuàng)建 Bucket,假設(shè)創(chuàng)建了 Bucket 名稱為 mybucket 然后在這個 Bucket 下創(chuàng)建一個目錄 test

假設(shè)您上傳到了mybucket這個Bucket下的test目錄下,則OSS路徑表示為: oss://mybucket/test/worker.tar.gz。

1.2.2. 使用控制臺提交作業(yè)

打開 提交作業(yè)頁面。

  • 按照表單提示,填寫作業(yè)名稱:first_job。

第1步
  • 拖拽一個任務(wù),按照下圖填寫表單, 其中ECS鏡像ID可以從這里獲取:使用鏡像

第2步
  • 然后點擊下面的 提交作業(yè) 按鈕, 即可提交成功。

  • 提交成功后,自動跳轉(zhuǎn)到作業(yè)列表頁面,您可以在這里看到你提交的作業(yè)狀態(tài)。

  • 等待片刻后作業(yè)運行完成,即可查看結(jié)果。

1.3. 使用 Python SDK

1.3.1. 將test.py打包上傳到云端OSS

同上一節(jié)。

1.3.2. 提交作業(yè)

from batchcompute import Client, ClientError
from batchcompute import CN_SHENZHEN as REGION

ACCESS_KEY_ID = 'your_access_key_id'          #需要配置
ACCESS_KEY_SECRET = 'your_access_key_secret'  #需要配置

job_desc = {
  "Name": "my_job_name",
  "Description": "hello test",
  "JobFailOnInstanceFail": true,
  "Priority": 0,
  "Type": "DAG",
  "DAG": {
    "Tasks": {
      "test": {
        "InstanceCount": 1,
        "MaxRetryCount": 0,
        "Parameters": {
          "Command": {
            "CommandLine": "python test.py",
            "PackagePath": "oss://mybucket/test/worker.tar.gz"
          },
          "StderrRedirectPath": "oss://mybucket/test/logs/",
          "StdoutRedirectPath": "oss://mybucket/test/logs/"
        },
        "Timeout": 21600,
        "AutoCluster": {
          "InstanceType": "ecs.sn1.medium",
          "ImageId": "img-ubuntu"
        }
      }
    },
    "Dependencies": {}
  }
}

client = Client(REGION, ACCESS_KEY_ID, ACCESS_KEY_SECRET)
result = client.create_job(job_desc)
job_id = result.Id

....

更多關(guān)于 Python SDK 內(nèi)容,請參閱 Python SDK

1.4. 使用 Java SDK

1.4.1. 將test.py打包上傳到 OSS

同上一節(jié)。

1.4.2. 提交作業(yè)

import com.aliyuncs.batchcompute.main.v20151111.*;
import com.aliyuncs.batchcompute.model.v20151111.*;
import com.aliyuncs.batchcompute.pojo.v20151111.*;
import com.aliyuncs.exceptions.ClientException;

public class SubmitJob{

    String REGION = "cn-shenzhen";
    String ACCESS_KEY_ID = "";     //需要配置
    String ACCESS_KEY_SECRET = ""; //需要配置

    public static void main(String[] args) throws ClientException{
        JobDescription desc = new SubmitJob().getJobDesc();

        BatchCompute client = new BatchComputeClient(REGION, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
        CreateJobResponse res = client.createJob(desc);
        String jobId = res.getJobId();

        //...
    }

    private JobDescription getJobDesc() {
       JobDescription desc = new JobDescription();

       desc.setName("testJob");
       desc.setPriority(1);
       desc.setDescription("JAVA SDK TEST");
       desc.setType("DAG");
       desc.setJobFailOnInstanceFail(true);

       DAG dag = new DAG();

       dag.addTask(getTaskDesc());

       desc.setDag(dag);
       return desc;
   }

   private TaskDescription getTaskDesc() {
       TaskDescription task = new TaskDescription();

       task.setClusterId(gClusterId);
       task.setInstanceCount(1);
       task.setMaxRetryCount(0);
       task.setTaskName("test");
       task.setTimeout(10000);

       AutoCluster autoCluster = new AutoCluster();
       autoCluster.setImageId("img-ubuntu");
       autoCluster.setInstanceType("ecs.sn1.medium");
    //   autoCluster.setResourceType("OnDemand");

       task.setAutoCluster(autoCluster);

       Parameters parameters = new Parameters();
       Command cmd = new Command();
       cmd.setCommandLine("python test.py");
    //    cmd.addEnvVars("a", "b");

       cmd.setPackagePath("oss://mybucket/test/worker.tar.gz");
       parameters.setCommand(cmd);
       parameters.setStderrRedirectPath("oss://mybucket/test/logs/");
       parameters.setStdoutRedirectPath("oss://mybucket/test/logs/");
    //    InputMappingConfig input = new InputMappingConfig();
    //    input.setLocale("GBK");
    //    input.setLock(true);
    //    parameters.setInputMappingConfig(input);

       task.setParameters(parameters);

    //    task.addInputMapping("oss://my-bucket/disk1/", "/home/admin/disk1/");
    //    task.addOutputtMapping("/home/admin/disk2/", "oss://my-bucket/disk2/");
    //    task.addLogMapping( "/home/admin/a.log","oss://my-bucket/a.log");

       return task;
   }
}

更多關(guān)于 Java SDK 內(nèi)容,請參閱 Java SDK

2. 批量計算 CommandLine

  • CommandLine不等同于SHELL,僅支持”程序+參數(shù)”方式,比如”python test.py”或”sh test.sh”。

  • 如果你想要執(zhí)行SHELL,可以使用”/bin/bash -c ‘cd /home/xx/ && python a.py’”。

  • 或者將Shell寫到一個sh腳本中如:test.sh, 然后用”sh test.sh”執(zhí)行。

CommandLine具體位置:

  • 命令行工具中 bcs sub <cmd> [job_name] [options] 的cmd。

  • 使用java sdk時 cmd.setCommandLine(cmd)中的cmd。

  • python sdk中的 taskName.Parameters.Command.CommandLine