From 9ee60a5b5a53e79b8fe5cbef320437e7f1d317b1 Mon Sep 17 00:00:00 2001 From: Dominic Gagne Date: Wed, 6 Nov 2024 11:21:17 -0800 Subject: [PATCH 1/3] release node v3 --- README.md | 34 ++++++++++++++++++++++++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a01367e..bfef2a6 100644 --- a/README.md +++ b/README.md @@ -273,6 +273,40 @@ In this release, we have abstracted these implementation details away and expose ## Release Notes +### Release 3.0.0 (November 6, 2024) +* New lease assignment / load balancing algorithm + * KCL 3.x introduces a new lease assignment and load balancing algorithm. It assigns leases among workers based on worker utilization metrics and throughput on each lease, replacing the previous lease count-based lease assignment algorithm. + * When KCL detects higher variance in CPU utilization among workers, it proactively reassigns leases from over-utilized workers to under-utilized workers for even load balancing. This ensures even CPU utilization across workers and removes the need to over-provision the stream processing compute hosts. +* Optimized DynamoDB RCU usage + * KCL 3.x optimizes DynamoDB read capacity unit (RCU) usage on the lease table by implementing a global secondary index with leaseOwner as the partition key. This index mirrors the leaseKey attribute from the base lease table, allowing workers to efficiently discover their assigned leases by querying the index instead of scanning the entire table. + * This approach significantly reduces read operations compared to earlier KCL versions, where workers performed full table scans, resulting in higher RCU consumption. +* Graceful lease handoff + * KCL 3.x introduces a feature called "graceful lease handoff" to minimize data reprocessing during lease reassignments. Graceful lease handoff allows the current worker to complete checkpointing of processed records before transferring the lease to another worker. For graceful lease handoff, you should implement checkpointing logic within the existing `shutdownRequested()` method. + * This feature is enabled by default in KCL 3.x, but you can turn off this feature by adjusting the configuration property `isGracefulLeaseHandoffEnabled`. + * While this approach significantly reduces the probability of data reprocessing during lease transfers, it doesn't completely eliminate the possibility. To maintain data integrity and consistency, it's crucial to design your downstream consumer applications to be idempotent. This ensures that the application can handle potential duplicate record processing without adverse effects. +* New DynamoDB metadata management artifacts + * KCL 3.x introduces two new DynamoDB tables for improved lease management: + * Worker metrics table: Records CPU utilization metrics from each worker. KCL uses these metrics for optimal lease assignments, balancing resource utilization across workers. If CPU utilization metric is not available, KCL assigns leases to balance the total sum of shard throughput per worker instead. + * Coordinator state table: Stores internal state information for workers. Used to coordinate in-place migration from KCL 2.x to KCL 3.x and leader election among workers. + * Follow this [documentation](https://docs.aws.amazon.com/streams/latest/dev/kcl-migration-from-2-3.html#kcl-migration-from-2-3-IAM-permissions) to add required IAM permissions for your KCL application. +* Other improvements and changes + * Dependency on the AWS SDK for Java 1.x has been fully removed. + * The Glue Schema Registry integration functionality no longer depends on AWS SDK for Java 1.x. Previously, it required this as a transient dependency. + * Multilangdaemon has been upgraded to use AWS SDK for Java 2.x. It no longer depends on AWS SDK for Java 1.x. + * `idleTimeBetweenReadsInMillis` (PollingConfig) now has a minimum default value of 200. + * This polling configuration property determines the [publishers](https://github.com/awslabs/amazon-kinesis-client/blob/master/amazon-kinesis-client/src/main/java/software/amazon/kinesis/retrieval/polling/PrefetchRecordsPublisher.java) wait time between GetRecords calls in both success and failure cases. Previously, setting this value below 200 caused unnecessary throttling. This is because Amazon Kinesis Data Streams supports up to five read transactions per second per shard for shared-throughput consumers. + * Shard lifecycle management is improved to deal with edge cases around shard splits and merges to ensure records continue being processed as expected. +* Migration + * The programming interfaces of KCL 3.x remain identical with KCL 2.x for an easier migration. For detailed migration instructions, please refer to the [Migrate consumers from KCL 2.x to KCL 3.x](https://docs.aws.amazon.com/streams/latest/dev/kcl-migration-from-2-3.html) page in the Amazon Kinesis Data Streams developer guide. +* Configuration properties + * New configuration properties introduced in KCL 3.x are listed in this [doc](https://github.com/awslabs/amazon-kinesis-client/blob/master/docs/kcl-configurations.md#new-configurations-in-kcl-3x). + * Deprecated configuration properties in KCL 3.x are listed in this [doc](https://github.com/awslabs/amazon-kinesis-client/blob/master/docs/kcl-configurations.md#discontinued-configuration-properties-in-kcl-3x). You need to keep the deprecated configuration properties during the migration from any previous KCL version to KCL 3.x. +* Metrics + * New CloudWatch metrics introduced in KCL 3.x are explained in the [Monitor the Kinesis Client Library with Amazon CloudWatch](https://docs.aws.amazon.com/streams/latest/dev/monitoring-with-kcl.html) in the Amazon Kinesis Data Streams developer guide. The following operations are newly added in KCL 3.x: + * `LeaseAssignmentManager` + * `WorkerMetricStatsReporter` + * `LeaseDiscovery` + ### Release 2.2.6 (April 25, 2024) * [PR #327](https://github.com/awslabs/amazon-kinesis-client-nodejs/pull/327) Upgraded amazon-kinesis-client from 2.5.5 to 2.5.8 * [PR #329](https://github.com/awslabs/amazon-kinesis-client-nodejs/pull/329) Upgraded aws-sdk from 2.1562.0 to 2.1603.0 diff --git a/package-lock.json b/package-lock.json index ae15d33..6380e73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "aws-kcl", - "version": "2.2.6", + "version": "3.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "aws-kcl", - "version": "2.2.6", + "version": "3.0.0", "license": "Apache-2.0", "dependencies": { "commander": "~12.0.0", diff --git a/package.json b/package.json index cea79b0..2fd36ea 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "aws-kcl", "description": "Kinesis Client Libray (KCL) in Node.js.", - "version": "2.2.6", + "version": "3.0.0", "author": { "name": "Amazon Web Services", "url": "http://aws.amazon.com/" From b5cc25b6475fd22ace328e0db911c877bfcf598d Mon Sep 17 00:00:00 2001 From: Dominic Gagne Date: Wed, 6 Nov 2024 12:04:09 -0800 Subject: [PATCH 2/3] update pom and configs for v3 --- pom.xml | 104 ++++++++++-------- .../basic_sample/consumer/sample.properties | 96 +++++++++++++++- 2 files changed, 151 insertions(+), 49 deletions(-) diff --git a/pom.xml b/pom.xml index 90e2635..8e0dd78 100644 --- a/pom.xml +++ b/pom.xml @@ -2,13 +2,12 @@ 4.0.0 - 2.5.8 - 2.25.11 - 1.12.512 + 2.25.64 + 3.0.0 4.1.108.Final - 2.0.12 - 2.14.1 - 1.5.3 + 2.0.6 + 2.13.5 + 1.3.14 @@ -31,6 +30,18 @@ dynamodb ${awssdk.version} + + + software.amazon.awssdk + dynamodb-enhanced + ${awssdk.version} + + + + com.amazonaws + dynamodb-lock-client + 1.3.0 + software.amazon.awssdk cloudwatch @@ -118,59 +129,59 @@ software.amazon.awssdk - http-auth + regions ${awssdk.version} software.amazon.awssdk - http-auth-spi + annotations ${awssdk.version} software.amazon.awssdk - http-auth-aws + utils ${awssdk.version} software.amazon.awssdk - identity-spi + apache-client ${awssdk.version} software.amazon.awssdk - checksums-spi + arns ${awssdk.version} - software.amazon.awssdk - checksums - ${awssdk.version} + software.amazon.awssdk + http-auth-spi + ${awssdk.version} - software.amazon.awssdk - regions - ${awssdk.version} + software.amazon.awssdk + http-auth + ${awssdk.version} - software.amazon.awssdk - annotations - ${awssdk.version} + software.amazon.awssdk + http-auth-aws + ${awssdk.version} - software.amazon.awssdk - utils - ${awssdk.version} + software.amazon.awssdk + checksums-spi + ${awssdk.version} - software.amazon.awssdk - apache-client - ${awssdk.version} + software.amazon.awssdk + checksums + ${awssdk.version} - software.amazon.awssdk - arns - ${awssdk.version} - + software.amazon.awssdk + identity-spi + ${awssdk.version} + io.netty netty-codec-http @@ -234,7 +245,7 @@ org.reactivestreams reactive-streams - 1.0.4 + 1.0.3 com.google.guava @@ -249,7 +260,7 @@ org.checkerframework checker-qual - 3.36.0 + 2.5.2 com.google.errorprone @@ -264,27 +275,27 @@ org.codehaus.mojo animal-sniffer-annotations - 1.23 + 1.20 com.google.protobuf protobuf-java - 3.25.3 + 4.27.5 org.apache.commons commons-lang3 - 3.12.0 + 3.14.0 org.slf4j slf4j-api - 2.0.12 + 2.0.13 io.reactivex.rxjava3 rxjava - 3.1.5 + 3.1.8 com.fasterxml.jackson.dataformat @@ -326,11 +337,6 @@ httpcore 4.4.15 - - com.amazonaws - aws-java-sdk-core - ${aws-java-sdk.version} - com.amazon.ion ion-java @@ -339,7 +345,13 @@ software.amazon.glue schema-registry-serde - 1.1.13 + 1.1.19 + + + com.amazonaws + aws-java-sdk-sts + + joda-time @@ -364,7 +376,7 @@ commons-io commons-io - 2.11.0 + 2.16.1 commons-logging @@ -374,7 +386,7 @@ org.apache.commons commons-collections4 - 4.2 + 4.4 commons-beanutils @@ -387,4 +399,4 @@ 3.2.2 - + diff --git a/samples/basic_sample/consumer/sample.properties b/samples/basic_sample/consumer/sample.properties index a8ccc2f..ce4fdf8 100644 --- a/samples/basic_sample/consumer/sample.properties +++ b/samples/basic_sample/consumer/sample.properties @@ -12,10 +12,12 @@ streamName = kclnodejssample applicationName = kclnodejssample # Users can change the credentials provider the KCL will use to retrieve credentials. -# The DefaultAWSCredentialsProviderChain checks several other providers, which is +# Expected key name (case-sensitive): +# AwsCredentialsProvider / AwsCredentialsProviderDynamoDB / AwsCredentialsProviderCloudWatch +# The DefaultCredentialsProvider checks several other providers, which is # described here: -# http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html -AWSCredentialsProvider = DefaultAWSCredentialsProviderChain +# https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/DefaultCredentialsProvider.html +AwsCredentialsProvider = DefaultCredentialsProvider # Appended to the user agent of the KCL. Does not impact the functionality of the # KCL in any other way. @@ -85,3 +87,91 @@ regionName = us-east-1 # By default, KCL will emit metrics for Operation, ShardId, and WorkerIdentifier dimensions # Specify the specific dimensions to emit metrics for #metricsEnabledDimensions = Operation,ShardId + +################### KclV3 configurations ################### +# NOTE : These are just test configurations to show how to customize +# all possible KCLv3 configurations. They are not necessarily the best +# default values to use for production. + +# Coordinator config +# Version the KCL needs to operate in. For more details check the KCLv3 migration +# documentation. Default is CLIENT_VERSION_CONFIG_3X +# clientVersionConfig = +# Configurations to control how the CoordinatorState DDB table is created +# Default name is applicationName-CoordinatorState in PAY_PER_REQUEST, +# with PITR and deletion protection disabled and no tags +# coordinatorStateTableName = +# coordinatorStateBillingMode = +# coordinatorStateReadCapacity = +# coordinatorStateWriteCapacity = +# coordinatorStatePointInTimeRecoveryEnabled = +# coordinatorStateDeletionProtectionEnabled = +# coordinatorStateTags = + +# Graceful handoff config - tuning of the shutdown behavior during lease transfers +# default values are 30000 and true respectively +# gracefulLeaseHandoffTimeoutMillis = +# isGracefulLeaseHandoffEnabled = + +# WorkerMetricStats table config - control how the DDB table is created +# Default name is applicationName-WorkerMetricStats in PAY_PER_REQUEST, +# with PITR and deletion protection disabled and no tags +# workerMetricsTableName = +# workerMetricsBillingMode = +# workerMetricsReadCapacity = +# workerMetricsWriteCapacity = +# workerMetricsPointInTimeRecoveryEnabled = +# workerMetricsDeletionProtectionEnabled = +# workerMetricsTags = + +# WorkerUtilizationAwareAssignment config - tune the new KCLv3 Lease balancing algorithm +# +# frequency of capturing worker metrics in memory. Default is 1s +# inMemoryWorkerMetricsCaptureFrequencyMillis = + +# frequency of reporting worker metric stats to storage. Default is 30s +# workerMetricsReporterFreqInMillis = + +# No. of metricStats that are persisted in WorkerMetricStats ddb table, default is 10 +# noOfPersistedMetricsPerWorkerMetrics = + +# Disable use of worker metrics to balance lease, default is false. +# If it is true, the algorithm balances lease based on worker's processing throughput. +# disableWorkerMetrics = + +# Max throughput per host 10 MBps, to limit processing to the given value +# Default is unlimited. + +# maxThroughputPerHostKBps = +# Dampen the load that is rebalanced during lease re-balancing, default is 60% +# dampeningPercentage = +# Configures the allowed variance range for worker utilization. The upper +# limit is calculated as average * (1 + reBalanceThresholdPercentage/100). +# The lower limit is average * (1 - reBalanceThresholdPercentage/100). If +# any worker's utilization falls outside this range, lease re-balancing is +# triggered. The re-balancing algorithm aims to bring variance within the +# specified range. It also avoids thrashing by ensuring the utilization of +# the worker receiving the load after re-balancing doesn't exceed the fleet +# average. This might cause no re-balancing action even the utilization is +# out of the variance range. The default value is 10, representing +/-10% +# variance from the average value. +# reBalanceThresholdPercentage = + +# Whether at-least one lease must be taken from a high utilization worker +# during re-balancing when there is no lease assigned to that worker which has +# throughput is less than or equal to the minimum throughput that needs to be +# moved away from that worker to bring the worker back into the allowed variance. +# Default is true. +# allowThroughputOvershoot = + +# Lease assignment is performed every failoverTimeMillis but re-balance will +# be attempted only once in 5 times based on the below config. Default is 3. +# varianceBalancingFrequency = + +# Alpha value used for calculating exponential moving average of worker's metricStats. +# workerMetricsEMAAlpha = +# Duration after which workerMetricStats entry from WorkerMetricStats table will +# be cleaned up. +# Duration format examples: PT15M (15 mins) PT10H (10 hours) P2D (2 days) +# Refer to Duration.parse javadocs for more details +# staleWorkerMetricsEntryCleanupDuration = From 6fffa0cf585a5a81f63db2f0550d2890aadb2077 Mon Sep 17 00:00:00 2001 From: Dominic Gagne Date: Wed, 6 Nov 2024 12:54:28 -0800 Subject: [PATCH 3/3] update README for v3 release --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bfef2a6..aeda37f 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ Amazon KCL for Node.js uses [MultiLangDaemon][multi-lang-daemon] provided by [Am ### Setting Up the Environment Before running the samples, make sure that your environment is configured to allow the samples to use your [AWS Security Credentials](http://docs.aws.amazon.com/general/latest/gr/aws-security-credentials.html), which are used by [MultiLangDaemon][multi-lang-daemon] to interact with AWS services. -By default, the [MultiLangDaemon][multi-lang-daemon] uses the [DefaultAWSCredentialsProviderChain][DefaultAWSCredentialsProviderChain], so make your credentials available to one of the credentials providers in that provider chain. There are several ways to do this. You can provide credentials through a `~/.aws/credentials` file or through environment variables (**AWS\_ACCESS\_KEY\_ID** and **AWS\_SECRET\_ACCESS\_KEY**). If you're running on Amazon EC2, you can associate an IAM role with your instance with appropriate access. +By default, the [MultiLangDaemon][multi-lang-daemon] uses the [DefaultCredentialsProvider][DefaultCredentialsProvider], so make your credentials available to one of the credentials providers in that provider chain. There are several ways to do this. You can provide credentials through a `~/.aws/credentials` file or through environment variables (**AWS\_ACCESS\_KEY\_ID** and **AWS\_SECRET\_ACCESS\_KEY**). If you're running on Amazon EC2, you can associate an IAM role with your instance with appropriate access. For more information about [Amazon Kinesis][amazon-kinesis] and the client libraries, see the [Amazon Kinesis documentation][amazon-kinesis-docs] as well as the [Amazon Kinesis forums][kinesis-forum]. @@ -423,7 +423,7 @@ __Updating minimum requirement for the JDK version to 8__ [amazon-kinesis-python-github]: https://github.com/awslabs/amazon-kinesis-client-python [amazon-kinesis-ruby-github]: https://github.com/awslabs/amazon-kinesis-client-ruby [multi-lang-daemon]: https://github.com/awslabs/amazon-kinesis-client/blob/master/src/main/java/com/amazonaws/services/kinesis/multilang/package-info.java -[DefaultAWSCredentialsProviderChain]: http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html +[DefaultCredentialsProvider]: https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/DefaultCredentialsProvider.html [kinesis-forum]: http://developer.amazonwebservices.com/connect/forum.jspa?forumID=169 [aws-console]: http://aws.amazon.com/console/ [jvm]: http://java.com/en/download/