blob: 4968e12e9ac9a7b0d2c0b844b28dbae301da35e7 [file]
---
redirect_to:
- https://docs.datastax.com/en/developer/nodejs-driver/latest/features/execution-profiles/
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="DataStax Nodejs Driver for Apache Cassandra">
<meta name="author" content="DataStax">
<title>DataStax Nodejs Driver - Execution Profiles (experimental)</title>
<link rel="icon" href="../../favicon.ico">
<link rel="apple-touch-icon" href="../../favicon.png">
<link href="../../css/style.css" rel="stylesheet">
<link href="../../css/pygments.css" rel="stylesheet">
<link href="../../css/hotkeys.css" rel="stylesheet">
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body ng-app="docs" data-spy="scroll" data-target="#table-of-contents" data-offset="69">
<header class="container-fluid navbar">
<div class="row">
<div class="col-sm-4">
<a class="navbar-brand" href="../../"><img alt="Brand" src="../../img/logo.png">DataStax Nodejs Driver</a>
</div>
<div class="col-md-4 col-md-offset-4">
<div class="row">
<div class="col-md-12">
<ul class="list-inline" role="nav">
<li><a href="https://academy.datastax.com/" class="navbar-link">DataStax Academy</a></li>
<li><a href="http://www.datastax.com/dev/blog" class="navbar-link">Tech Blog</a></li>
<li><a href="http://www.datastax.com/what-we-offer/products-services/support" class="navbar-link">Support</a></li>
</ul>
</div>
</div>
<div class="row">
<div class="col-md-8">
<form id="search" class="form-search dropdown visible-lg-block" ng-controller="search" ng-class="{open: hasResults}" role="search" ng-submit="submit()" data-spy="affix" data-offset-top="130">
<div class="form-group has-feedback">
<input type="search" class="form-control input-sm mousetrap" placeholder="Search..." ng-model="q" ng-change="search('v3.1')" ng-disabled="!searchReady" disabled data-hotkey="{down: moveDown, up: moveUp, esc: reset}" data-search>
</div>
<ul class="dropdown-menu search-results" role="menu">
<li ng-repeat="result in results" ng-class="{'bg-warning': $index == current}"><a ng-href="{{basePath}}{{result.path}}"><span ng-bind-html="summary(result)"></span></a></li>
</ul>
</form>
</div>
<div class="col-md-4">
<a href="http://www.datastax.com/download" class="btn btn-primary btn-sm">Download</a>
</div>
</div>
</div>
</div>
<div class="row crumbs-wrapper">
<div class="col-md-12">
<nav id="crumbs" data-spy="affix" data-offset-top="130">
<ol class="breadcrumb">
<li>
<div class="btn-group">
<button id="current-version" class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
v3.1
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="current-version">
<li class="disabled"><a href="./">v3.1</a></li>
<li><a href="../../v3.0/">v3.0</a></li>
</ul>
</div>
</li>
<li><a href="../../">Home</a></li>
<li><a href="../">Features</a></li>
<li class="active">Execution Profiles (experimental)</li>
<li class="dropdown" id="table-of-contents">
<div class="btn-group">
<button id="current-section" type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
Jump to&#8230; <span class="caret"></span><span class="sr-only">Table of Contents</span>
</button>
<ul class="dropdown-menu nav nav-pills nav-stacked">
<li><a href="#execution-profiles-experimental">Page Top <span class="glyphicon glyphicon-chevron-up" aria-hidden="true"></span></a></li>
<li>
<a href="#using-execution-profiles">Using Execution Profiles
</a><ul class="nav nav-pills nav-stacked">
<li>
<a href="#initializing-cluster-with-profiles">Initializing cluster with profiles
</a><ul class="nav nav-pills nav-stacked"><li><a href="#default-execution-profile">Default execution profile
</a></li></ul>
</li>
<li><a href="#using-an-execution-profile-by-name">Using an execution profile by name
</a></li>
<li><a href="#using-an-execution-profile-by-instance">Using an execution profile by instance
</a></li>
<li><a href="#using-default-execution-profile">Using default execution profile
</a></li>
</ul>
</li>
</ul>
</div>
</li>
</ol>
</nav>
</div>
</div>
</header>
<div class="container-fluid" id="content">
<div class="row">
<div class="col-md-3">
<div id="navigation" class="side-nav" role="tablist" aria-multiselectable="true">
<h3>Contents</h3>
<ul class="nav nav-pills nav-stacked">
<li class="active">
<a href="../">Features <small>page</small></a>
<ul class="nav nav-pills nav-stacked">
<li>
<a href="../address-resolution/">Address resolution <small>page</small></a>
</li>
<li>
<a href="../batch/">Batch statements <small>page</small></a>
</li>
<li>
<a href="../datatypes/">CQL data types to JavaScript types <small>page</small></a>
</li>
<li>
<a href="../metadata/">Cluster and schema metadata <small>page</small></a>
</li>
<li>
<a href="../connection-pooling/">Connection pooling <small>page</small></a>
</li>
<li class="active">
<a href="./" class="current">Execution Profiles (experimental) <small>page</small></a>
</li>
<li>
<a href="../paging/">Fetching large result sets <small>page</small></a>
</li>
<li>
<a href="../native-protocol/">Native protocol <small>page</small></a>
</li>
<li>
<a href="../parameterized-queries/">Parameterized queries <small>page</small></a>
</li>
<li>
<a href="../query-warnings/">Query warnings <small>page</small></a>
</li>
<li>
<a href="../tuning-policies/">Tuning policies <small>page</small></a>
</li>
<li>
<a href="../udfs/">User-defined functions and aggregates <small>page</small></a>
</li>
</ul>
</li>
<li>
<a href="../../faq/">Frequently Asked Questions <small>page</small></a>
</li>
<li>
<a href="../../getting-started/">Getting started <small>page</small></a>
</li>
<li>
<a href="../../coding-rules/">Three simple rules for coding with the driver <small>page</small></a>
</li>
</ul>
</div>
</div>
<div class="col-md-9 content">
<h1 id="execution-profiles-experimental" class="target">Execution Profiles (experimental)<a class="anchor" href="#execution-profiles-experimental" aria-hidden="true"><span class="glyphicon glyphicon-link"></span></a>
</h1>
<p>Execution profiles provide a mechanism to group together a set of configuration options and reuse them across different
query executions. These options include:</p>
<ul>
<li>Load balancing policy</li>
<li>Retry policy</li>
<li>Consistency levels</li>
<li>Per-host request timeout</li>
</ul>
<p>Execution profiles API is being introduced to help deal with the exploding number of configuration options, especially
as the database platform evolves into more complex workloads. It is first introduced in an experimental capacity, in
order to take advantage of it in existing projects, and to gauge interest and feedback in the community.</p>
<p>This document explains how Execution Profiles relate to existing settings, and shows how to use the new profiles for
request execution.</p>
<h2 id="using-execution-profiles" class="target">Using Execution Profiles<a class="anchor" href="#using-execution-profiles" aria-hidden="true"><span class="glyphicon glyphicon-link"></span></a>
</h2>
<h3 id="initializing-cluster-with-profiles" class="target">Initializing cluster with profiles<a class="anchor" href="#initializing-cluster-with-profiles" aria-hidden="true"><span class="glyphicon glyphicon-link"></span></a>
</h3>
<p>Execution profiles should be created when creating the <code>Client</code> instance with a name that identifies it and the settings
that apply to the profile.</p>
<pre class="highlight"><code><span class="kr">const</span> <span class="nx">aggregationProfile</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ExecutionProfile</span><span class="p">(</span><span class="s1">'aggregation'</span><span class="p">,</span> <span class="p">{</span>
<span class="na">consistency</span><span class="p">:</span> <span class="nx">consistency</span><span class="p">.</span><span class="nx">localQuorum</span><span class="p">,</span>
<span class="na">loadBalancing</span><span class="p">:</span> <span class="k">new</span> <span class="nx">DCAwareRoundRobinPolicy</span><span class="p">(</span><span class="s1">'us-west'</span><span class="p">)</span>
<span class="na">retry</span><span class="p">:</span> <span class="nx">myRetryPolicy</span><span class="p">,</span>
<span class="na">readTimeout</span><span class="p">:</span> <span class="mi">30000</span><span class="p">,</span>
<span class="na">serialConsistency</span><span class="p">:</span> <span class="nx">consistency</span><span class="p">.</span><span class="nx">localSerial</span>
<span class="p">});</span>
<span class="kr">const</span> <span class="nx">client</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Client</span><span class="p">({</span>
<span class="na">contactPoints</span><span class="p">:</span> <span class="p">[</span><span class="s1">'host1'</span><span class="p">],</span>
<span class="na">profiles</span><span class="p">:</span> <span class="p">[</span> <span class="nx">aggregationProfile</span> <span class="p">]</span>
<span class="p">});</span>
</code></pre>
<p>Note that while the above options are all the supported settings on the execution profiles, you can specify only the
ones that are required for the executions, using the <code>'default'</code> profile to fill the rest of the options.</p>
<h4 id="default-execution-profile" class="target">Default execution profile<a class="anchor" href="#default-execution-profile" aria-hidden="true"><span class="glyphicon glyphicon-link"></span></a>
</h4>
<p>You can define a default profile, using the name <code>'default'</code>:</p>
<pre class="highlight"><code><span class="kr">const</span> <span class="nx">client</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Client</span><span class="p">({</span>
<span class="na">contactPoints</span><span class="p">:</span> <span class="p">[</span><span class="s1">'host1'</span><span class="p">],</span>
<span class="na">profiles</span><span class="p">:</span> <span class="p">[</span>
<span class="k">new</span> <span class="nx">ExecutionProfile</span><span class="p">(</span><span class="s1">'default'</span><span class="p">,</span> <span class="p">{</span>
<span class="na">consistency</span><span class="p">:</span> <span class="nx">consistency</span><span class="p">.</span><span class="nx">one</span><span class="p">,</span>
<span class="na">readTimeout</span><span class="p">:</span> <span class="mi">10000</span>
<span class="p">}),</span>
<span class="k">new</span> <span class="nx">ExecutionProfile</span><span class="p">(</span><span class="s1">'time-series'</span><span class="p">,</span> <span class="p">{</span>
<span class="na">consistency</span><span class="p">:</span> <span class="nx">consistency</span><span class="p">.</span><span class="nx">localQuorum</span>
<span class="p">})</span>
<span class="p">]</span>
<span class="p">});</span>
</code></pre>
<p>The default profile will be used to fill the unspecified options in the rest of the profiles. In the above example, the
read timeout for the profile named <code>'time-series'</code> will be the one defined in the default profile (10,000 ms).</p>
<p>For the settings that are not specified in the default profile, the driver will use the default <code>Client</code> options.</p>
<h3 id="using-an-execution-profile-by-name" class="target">Using an execution profile by name<a class="anchor" href="#using-an-execution-profile-by-name" aria-hidden="true"><span class="glyphicon glyphicon-link"></span></a>
</h3>
<p>Use the name to specify which profile you want to use for the execution.</p>
<pre class="highlight"><code><span class="nx">client</span><span class="p">.</span><span class="nx">execute</span><span class="p">(</span><span class="nx">query</span><span class="p">,</span> <span class="nx">params</span><span class="p">,</span> <span class="p">{</span> <span class="na">executionProfile</span><span class="p">:</span> <span class="s1">'aggregation'</span> <span class="p">},</span> <span class="nx">callback</span><span class="p">);</span>
</code></pre>
<h3 id="using-an-execution-profile-by-instance" class="target">Using an execution profile by instance<a class="anchor" href="#using-an-execution-profile-by-instance" aria-hidden="true"><span class="glyphicon glyphicon-link"></span></a>
</h3>
<p>You can also use the <code>ExecutionProfile</code> instance.</p>
<pre class="highlight"><code><span class="nx">client</span><span class="p">.</span><span class="nx">execute</span><span class="p">(</span><span class="nx">query</span><span class="p">,</span> <span class="nx">params</span><span class="p">,</span> <span class="p">{</span> <span class="na">executionProfile</span><span class="p">:</span> <span class="nx">aggregationProfile</span> <span class="p">},</span> <span class="nx">callback</span><span class="p">);</span>
</code></pre>
<h3 id="using-default-execution-profile" class="target">Using default execution profile<a class="anchor" href="#using-default-execution-profile" aria-hidden="true"><span class="glyphicon glyphicon-link"></span></a>
</h3>
<p>When the execution profile is not provided in the options, the default execution profile is used.</p>
<pre class="highlight"><code><span class="nx">client</span><span class="p">.</span><span class="nx">execute</span><span class="p">(</span><span class="nx">query</span><span class="p">,</span> <span class="nx">params</span><span class="p">,</span> <span class="nx">callback</span><span class="p">);</span>
</code></pre>
</div>
</div>
</div>
<footer class="container text-muted">
<ul class="list-inline">
<li>
<a href="https://github.com/datastax/nodejs-driver/">Code</a>
</li>
<li>·</li>
<li>
<a href="http://datastax.github.io/nodejs-driver/">Docs</a>
</li>
<li>·</li>
<li>
<a href="https://datastax-oss.atlassian.net/projects/NODEJS/issues">Issues</a>
</li>
<li>·</li>
<li>
<a href="https://groups.google.com/a/lists.datastax.com/forum/#!forum/nodejs-driver-user">Mailing List</a>
</li>
<li>·</li>
<li>
<a href="irc://irc.freenode.net/datastax-drivers">IRC Channel</a>
</li>
<li>·</li>
<li>
<a href="https://www.npmjs.org/package/cassandra-driver">Npm</a>
</li>
</ul>
</footer>
<script src="../../js/jquery.js"></script>
<script src="../../js/bootstrap.js"></script>
<script src="../../js/angular.js"></script>
<script src="../../js/mousetrap.js"></script>
<script src="../../js/hotkeys.js"></script>
<script src="../../js/ZeroClipboard.js"></script>
<script src="../../js/lunr.js"></script>
<script src="../../js/app.js"></script>
</body>
</html>