Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ private void createClients() {
.connectionPolicy(configuration.getConnectionPolicy())
.consistencyLevel(configuration.getConsistencyLevel())
.connectionReuseAcrossClientsEnabled(true)
.returnMinimalResponse(configuration.isReturnMinimalResponse())
.buildAsyncClient();
List<PojoizedJson> docsToRead = new ArrayList<>();
CosmosAsyncDatabase cosmosAsyncDatabase = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ abstract class AsyncBenchmark<T> {
.key(cfg.getMasterKey())
.connectionPolicy(cfg.getConnectionPolicy())
.consistencyLevel(cfg.getConsistencyLevel())
.returnMinimalResponse(cfg.isReturnMinimalResponse())
.buildAsyncClient();
configuration = cfg;
logger = LoggerFactory.getLogger(this.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class Configuration {
@Parameter(names = "-throughput", description = "provisioned throughput for test container")
private int throughput = 100000;

@Parameter(names = "-returnMinimalResponse", description = "returns minimal response on document write operations")
private boolean returnMinimalResponse = false;

@Parameter(names = "-operation", description = "Type of Workload:\n"
+ "\tReadThroughput- run a READ workload that prints only throughput *\n"
+ "\tReadThroughputWithMultipleClients - run a READ workload that prints throughput and latency for multiple client read.*\n"
Expand Down Expand Up @@ -264,6 +267,10 @@ ConsistencyLevel getConsistencyLevel() {
return consistencyLevel;
}

boolean isReturnMinimalResponse() {
return returnMinimalResponse;
}

String getDatabaseId() {
return databaseId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public static void main(String[] args) throws Exception {
return;
}

validateConfiguration(cfg);

if (cfg.isSync()) {
syncBenchmark(cfg);
} else {
Expand All @@ -44,6 +46,19 @@ public static void main(String[] args) throws Exception {
}
}

private static void validateConfiguration(Configuration cfg) {
switch (cfg.getOperationType()) {
case WriteLatency:
case WriteThroughput:
break;
default:
if (cfg.isReturnMinimalResponse()) {
throw new IllegalArgumentException("returnMinimalResponse parameter can only be set to true " +
"for write latency and write throughput operations");
}
}
}

private static void syncBenchmark(Configuration cfg) throws Exception {
LOGGER.info("Sync benchmark ...");
SyncBenchmark benchmark = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public T apply(T o, Throwable throwable) {
.key(cfg.getMasterKey())
.connectionPolicy(cfg.getConnectionPolicy())
.consistencyLevel(cfg.getConsistencyLevel())
.returnMinimalResponse(cfg.isReturnMinimalResponse())
.buildClient();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public static CosmosAsyncClient getCosmosClient() {
.key(SampleConfigurations.MASTER_KEY)
.connectionPolicy(ConnectionPolicy.getDefaultPolicy())
.consistencyLevel(ConsistencyLevel.EVENTUAL)
.returnMinimalResponse(false)
Comment thread
kushagraThapar marked this conversation as resolved.
Outdated
.buildAsyncClient();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public final class CosmosAsyncClient implements Closeable {
private final CosmosKeyCredential cosmosKeyCredential;
private final boolean sessionCapturingOverride;
private final boolean enableTransportClientSharing;
private final boolean returnMinimalResponse;

CosmosAsyncClient(CosmosClientBuilder builder) {
this.configs = builder.configs();
Expand All @@ -61,6 +62,7 @@ public final class CosmosAsyncClient implements Closeable {
this.cosmosKeyCredential = builder.getKeyCredential();
this.sessionCapturingOverride = builder.isSessionCapturingOverrideEnabled();
this.enableTransportClientSharing = builder.isConnectionReuseAcrossClientsEnabled();
this.returnMinimalResponse = builder.isReturnMinimalResponse();
this.asyncDocumentClient = new AsyncDocumentClient.Builder()
.withServiceEndpoint(this.serviceEndpoint)
.withMasterKeyOrResourceToken(this.keyOrResourceToken)
Expand All @@ -71,6 +73,7 @@ public final class CosmosAsyncClient implements Closeable {
.withTokenResolver(this.cosmosAuthorizationTokenResolver)
.withCosmosKeyCredential(this.cosmosKeyCredential)
.withTransportClientSharing(this.enableTransportClientSharing)
.withReturnMinimalResponse(this.returnMinimalResponse)
.build();
}

Expand Down Expand Up @@ -163,6 +166,20 @@ CosmosKeyCredential cosmosKeyCredential() {
return cosmosKeyCredential;
}

/**
* Gets the boolean which indicates whether to only return the headers and status code in Cosmos DB response
* in case of Create, Update and Delete operations on CosmosItem.
*
* If true, this removes the resource from response. It reduces networking
* and CPU load by not sending the resource back over the network and serializing it
* on the client.
*
* @return a boolean indicating whether resource will be included in the response or not
*/
boolean isReturnMinimalResponse() {
Comment thread
kushagraThapar marked this conversation as resolved.
Outdated
return returnMinimalResponse;
}

/**
* CREATE a Database if it does not already exist on the service
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public static CosmosClientBuilder cloneCosmosClientBuilder(CosmosClientBuilder b
.keyCredential(builder.getKeyCredential())
.permissions(builder.getPermissions())
.authorizationTokenResolver(builder.getAuthorizationTokenResolver())
.resourceToken(builder.getResourceToken());
.resourceToken(builder.getResourceToken())
.returnMinimalResponse(builder.isReturnMinimalResponse());

return copy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class CosmosClientBuilder {
private CosmosKeyCredential cosmosKeyCredential;
private boolean sessionCapturingOverrideEnabled;
private boolean connectionReuseAcrossClientsEnabled;
private boolean returnMinimalResponse = true;

/**
* Instantiates a new Cosmos client builder.
Expand Down Expand Up @@ -291,6 +292,39 @@ public CosmosClientBuilder keyCredential(CosmosKeyCredential cosmosKeyCredential
return this;
}

/**
* Gets the boolean which indicates whether to only return the headers and status code in Cosmos DB response
* in case of Create, Update and Delete operations on CosmosItem.
*
* If true, this removes the resource from response. It reduces networking
* and CPU load by not sending the resource back over the network and serializing it
* on the client.
*
* By-default, this is true.
*
* @return a boolean indicating whether resource will be included in the response or not
*/
boolean isReturnMinimalResponse() {
return returnMinimalResponse;
}

/**
* Sets the boolean to only return the headers and status code in Cosmos DB response
* in case of Create, Update and Delete operations on CosmosItem.
*
* If set to true, this removes the resource from response. It reduces networking
* and CPU load by not sending the resource back over the network and serializing it on the client.
Comment thread
kushagraThapar marked this conversation as resolved.
*
* By-default, this is true.
*
* @param returnMinimalResponse a boolean indicating whether resource will be included in the response or not
* @return current cosmosClientBuilder
*/
public CosmosClientBuilder returnMinimalResponse(boolean returnMinimalResponse) {
this.returnMinimalResponse = returnMinimalResponse;
return this;
}

/**
* Builds a cosmos configuration object with the provided properties
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Builder {
CosmosKeyCredential cosmosKeyCredential;
boolean sessionCapturingOverride;
boolean transportClientSharing;
boolean returnMinimalResponse;

public Builder withServiceEndpoint(String serviceEndpoint) {
try {
Expand Down Expand Up @@ -158,6 +159,11 @@ public Builder withCosmosKeyCredential(CosmosKeyCredential cosmosKeyCredential)
return this;
}

public Builder withReturnMinimalResponse(boolean returnMinimalResponse) {
this.returnMinimalResponse = returnMinimalResponse;
return this;
}

/**
* This method will accept functional interface TokenResolver which helps in generation authorization
* token per request. AsyncDocumentClient can be successfully initialized with this API without passing any MasterKey, ResourceToken or PermissionFeed.
Expand Down Expand Up @@ -187,15 +193,16 @@ public AsyncDocumentClient build() {
"cannot buildAsyncClient client without key credential");

RxDocumentClientImpl client = new RxDocumentClientImpl(serviceEndpoint,
masterKeyOrResourceToken,
permissionFeed,
connectionPolicy,
desiredConsistencyLevel,
configs,
cosmosAuthorizationTokenResolver,
cosmosKeyCredential,
sessionCapturingOverride,
transportClientSharing);
masterKeyOrResourceToken,
permissionFeed,
connectionPolicy,
desiredConsistencyLevel,
configs,
cosmosAuthorizationTokenResolver,
cosmosKeyCredential,
sessionCapturingOverride,
transportClientSharing,
returnMinimalResponse);
client.init();
return client;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ public static class SubStatusCodes {
}

public static class HeaderValues {
public static final String NoCache = "no-cache";
public static final String NO_CACHE = "no-cache";
public static final String PREFER_RETURN_MINIMAL = "return=minimal";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,17 @@ public String getCosmosResponseDiagnosticString() {
return cosmosResponseRequestDiagnosticStatistics.toString();
}

/**
* Gets the ETag from the response headers.
*
* Null in case of delete operation.
*
* @return ETag
*/
public String getETag() {
return this.response.getResponseHeaders().get(HttpConstants.HttpHeaders.E_TAG);
}

long getCurrentQuotaHeader(String headerName) {
if (this.usageHeaders.size() == 0 &&
!StringUtils.isEmpty(this.getMaxResourceQuota()) &&
Expand Down
Loading