Skip to content

Commit

Permalink
chore: Add SDK readme. (#87)
Browse files Browse the repository at this point in the history
* chore: Add SDK readme.

* fix: Split cohort_sdk_client readme into fiew files. Add more TypeScript types to SDK

* fix: Split cohort_sdk_client readme into fiew files. Add more TypeScript types to SDK

* fix: Remove optionalDependencies from sdk client

* chore: Merge initiator and replicator API docs back into sd_client readme

* fix: Add more types to Replicator.run()

* chore: Update readme

* fix: Typos in readme, pass accounts argument to initiator js example.

* fix: Fix data types in Initiator JS; update Readme. Reset client SDK version to default.
  • Loading branch information
fmarek-kindred authored Oct 17, 2023
1 parent c76a702 commit ab815a2
Show file tree
Hide file tree
Showing 15 changed files with 389 additions and 99 deletions.
4 changes: 2 additions & 2 deletions cohort_banking_initiator_js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,6 @@ npm start
```
cd $TALOS/cohort_banking_initiator_js
# Genrate 1000 transation requests at the rate of 500 TPS
npm start count=1000 rate=500
# Genrate 1000 transation requests at the rate of 500 TPS, pick accounts from dataset containing 10k bank accounts
npm start count=1000 rate=500 accounts=10000
```
62 changes: 18 additions & 44 deletions cohort_banking_initiator_js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cohort_banking_initiator_js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"typescript": "^5.1.6"
},
"dependencies": {
"@kindredgroup/cohort_sdk_client": "^0.0.1-0ed84cd",
"@kindredgroup/cohort_sdk_client": "^0.0.1",
"pg": "^8.11.3",
"winston": "^3.10.0"
}
Expand Down
3 changes: 2 additions & 1 deletion cohort_banking_initiator_js/src/banking-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ export class BankingApp {
async () => {
const s = Date.now()
const newRequest = await this.createNewRequest(tx) as any
logger.info("%s", JSON.stringify(newRequest, null, 2))
const n = Date.now()
stateEnd = n - span_s
stateDuration = n - s
return { newRequest }
},
async (_e, request: OutOfOrderRequest) => {
async (request: OutOfOrderRequest) => {
const s = Date.now()
const r = await this.installOutOfOrder(tx, request) as any
const n = Date.now()
Expand Down
4 changes: 2 additions & 2 deletions cohort_banking_initiator_js/src/load-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export function createGeneratorService(settings: any): Worker {
}

if (!isMainThread) {
const { count, channelName, rate } = workerData.settings
const generator = new LoadGenerator(100_000, 100)
const { count, channelName, rate, accounts } = workerData.settings
const generator = new LoadGenerator(accounts, 100)
logger.info("Load generator will generate: %d transactions at the reate of %d TPS", count, rate.toFixed(2))

new Promise(async () => {
Expand Down
10 changes: 9 additions & 1 deletion cohort_banking_initiator_js/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const printMetrics = (spans: Array<any>) => {
class LaunchParams {
transactionsCount: number = 10_000
targetRatePerSecond: number = 1_000
totalAccounts: number = 100_000

static parse(args: string[]): LaunchParams {
const params = new LaunchParams()
Expand All @@ -37,6 +38,8 @@ class LaunchParams {
params.transactionsCount = parseInt(arg.replaceAll("count=", ""))
} else if (arg.startsWith("rate")) {
params.targetRatePerSecond = parseInt(arg.replaceAll("rate=", ""))
} else if (arg.startsWith("accounts")) {
params.totalAccounts = parseInt(arg.replaceAll("accounts=", ""))
}
}

Expand Down Expand Up @@ -86,5 +89,10 @@ new Promise(async (resolve) => {
}
throw e
}
const _worker = createGeneratorService({ channelName: CHANNEL_NAME, count: params.transactionsCount, rate: params.targetRatePerSecond })
const _worker = createGeneratorService({
channelName: CHANNEL_NAME,
count: params.transactionsCount,
rate: params.targetRatePerSecond,
accounts: params.totalAccounts,
})
})
4 changes: 2 additions & 2 deletions cohort_banking_replicator_js/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Replicator, TalosSdkError } from "@kindredgroup/cohort_sdk_client"
import { JsStatemapAndSnapshot, Replicator, TalosSdkError } from "@kindredgroup/cohort_sdk_client"
import { Database } from "./database"

import { KAFKA_CONFIG } from "./cfg/config-kafka"
Expand All @@ -17,7 +17,7 @@ new Promise(async (_resolve) => {
try {
await replicator.run(
async () => await database.getSnapshot(),
async (_, params) => await database.install(params, { delayMs: 2, maxAttempts: 50 })
async (data: JsStatemapAndSnapshot) => await database.install(data, { delayMs: 2, maxAttempts: 50 })
)
logger.info("Replciator is running ...")
} catch (e) {
Expand Down
Loading

0 comments on commit ab815a2

Please sign in to comment.