diff --git a/README.md b/README.md index acd7a4e..bf5c214 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,40 @@ all languages. ## Release Notes +### Release 4.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 3.0.1 (April 24, 2024) * Upgraded amazon-kinesis-client from 2.4.4 to 2.5.8 * Upgraded netcoreapp from 5.0 to 6.0 @@ -224,7 +258,6 @@ all languages. [amazon-kinesis-ruby-github]: https://github.com/awslabs/amazon-kinesis-client-ruby [amazon-kinesis-nodejs-github]: https://github.com/awslabs/amazon-kinesis-client-nodejs [multi-lang-daemon]: https://github.com/awslabs/amazon-kinesis-client/blob/master/amazon-kinesis-client-multilang/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 [kinesis-forum]: http://developer.amazonwebservices.com/connect/forum.jspa?forumID=169 [master-zip]: https://github.com/awslabs/amazon-kinesis-client-net/archive/master.zip [aws-sdk-dotnet]: https://aws.amazon.com/sdk-for-net/ diff --git a/SampleConsumer/kcl.properties b/SampleConsumer/kcl.properties index d77fe2a..f32abe2 100644 --- a/SampleConsumer/kcl.properties +++ b/SampleConsumer/kcl.properties @@ -1,8 +1,13 @@ # The script that abides by the multi-language protocol. This script will # be executed by the MultiLangDaemon, which will communicate with this script # over STDIN and STDOUT according to the multi-language protocol. +# Ensure the path to the executable is correct: dotnet /SampleConsumer.dll executableName = dotnet SampleConsumer.dll +# The Stream arn: arn:aws:kinesis:::stream/ +# Important: streamArn takes precedence over streamName if both are set +streamArn = arn:aws:kinesis:us-east-5:000000000000:stream/kclnetsample + # The name of an Amazon Kinesis stream to process. streamName = kclnetsample @@ -12,10 +17,12 @@ streamName = kclnetsample applicationName = DotNetKinesisSample # 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. @@ -25,6 +32,11 @@ processingLanguage = C# # See http://docs.aws.amazon.com/kinesis/latest/APIReference/API_GetShardIterator.html#API_GetShardIterator_RequestSyntax initialPositionInStream = TRIM_HORIZON +# To specify an initial timestamp from which to start processing records, please specify timestamp value for 'initiatPositionInStreamExtended', +# and uncomment below line with right timestamp value. +# See more from 'Timestamp' under http://docs.aws.amazon.com/kinesis/latest/APIReference/API_GetShardIterator.html#API_GetShardIterator_RequestSyntax +#initialPositionInStreamExtended = 1636609142 + # The following properties are also available for configuring the KCL Worker that is created # by the MultiLangDaemon. @@ -81,3 +93,92 @@ regionName = us-east-1 # active threads set to the provided value. If a non-positive integer or no # value is provided a CachedThreadPool is used. #maxActiveThreads = 0 + +################### 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 = diff --git a/pom.xml b/pom.xml index e9cd6fe..8e0dd78 100644 --- a/pom.xml +++ b/pom.xml @@ -2,13 +2,12 @@ 4.0.0 - 2.5.8 - 2.19.16 - 1.12.468 + 2.25.64 + 3.0.0 4.1.108.Final 2.0.6 - 2.14.2 - 1.3.12 + 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 @@ -136,6 +147,41 @@ apache-client ${awssdk.version} + + software.amazon.awssdk + arns + ${awssdk.version} + + + software.amazon.awssdk + http-auth-spi + ${awssdk.version} + + + software.amazon.awssdk + http-auth + ${awssdk.version} + + + software.amazon.awssdk + http-auth-aws + ${awssdk.version} + + + software.amazon.awssdk + checksums-spi + ${awssdk.version} + + + software.amazon.awssdk + checksums + ${awssdk.version} + + + software.amazon.awssdk + identity-spi + ${awssdk.version} + io.netty netty-codec-http @@ -219,7 +265,7 @@ com.google.errorprone error_prone_annotations - 2.19.1 + 2.7.1 com.google.j2objc @@ -234,22 +280,22 @@ com.google.protobuf protobuf-java - 3.23.0 + 4.27.5 org.apache.commons commons-lang3 - 3.12.0 + 3.14.0 org.slf4j slf4j-api - 2.0.5 + 2.0.13 io.reactivex.rxjava3 rxjava - 3.1.5 + 3.1.8 com.fasterxml.jackson.dataformat @@ -291,11 +337,6 @@ httpcore 4.4.15 - - com.amazonaws - aws-java-sdk-core - ${aws-java-sdk.version} - com.amazon.ion ion-java @@ -304,7 +345,13 @@ software.amazon.glue schema-registry-serde - 1.1.13 + 1.1.19 + + + com.amazonaws + aws-java-sdk-sts + + joda-time @@ -329,12 +376,12 @@ commons-io commons-io - 2.11.0 + 2.16.1 commons-logging commons-logging - 1.2 + 1.1.3 org.apache.commons @@ -352,4 +399,4 @@ 3.2.2 - +