The amount of resources (virtual CPU cores and memory) of YARN containers is configurable before the start of the run of any application components. By setting these resources at runtime, instead of as part of the application code, you can remove the requirement for recompiling, repackaging, and redeploying of an application in order to simply change the resources used.

note

Note: Any resource specifications set directly in the application (such as shown in MapReduce and Resources) will be overridden as the runtime arguments take precedence.

Note: Any resource specifications set directly in the application (such as shown in MapReduce and Resources) will be overridden as the runtime arguments take precedence.

Virtual CPU Cores and Memory

The runtime system looks for these arguments:

These arguments can be set either as a runtime argument (which affects just the next run of a program) or as a preference (which affects all subsequent runs), as described in the Preferences Microservices documentation.

You can use the Preferences Microservices to set these arguments at various levels in the hierarchy (across a namespace, across programs in an application, for a specific program in a specific application, etc.). These will be persisted and used with each run of the application's programs.

Configuring Sub-components

For program types that have sub-components (such as MapReduce and Spark programs), a prefix can be added to limit the scope of the arguments.

MapReduce Program

Spark Program

Workflow

Examples

As an example, assume that you have deployed an application named MyApp in CDAP in the default namespace, and would like to set the memory used by its YARN containers.

$ curl -w"\n" -X PUT "http://example.com:11015/v3/preferences" \
    -H 'Content-Type: application/json' -d '{ "task.mapper.system.resources.memory": 2048 }'
> curl -X PUT "http://example.com:11015/v3/preferences" ^ -H 'Content-Type: application/json' -d "{ \"task.mapper.system.resources.memory\": 2048 }"

$ curl -w"\n" -X PUT "http://example.com:11015/v3/namespaces/default/apps/MyApp/mapreduce/MyMapReduce/preferences" \ -H 'Content-Type: application/json' -d '{ "task.mapper.system.resources.memory": 2048 }'
> curl -X PUT "http://example.com:11015/v3/namespaces/default/apps/MyApp/mapreduce/MyMapReduce/preferences" ^
    -H 'Content-Type: application/json' -d "{ \"task.mapper.system.resources.memory\": 2048 }"

These configurations can also be set through the CDAP UI, either as preferences or runtime arguments.