Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint all TS files base on our prettier for easier developer life, and added CI prettier step #1002

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions .github/workflows/lint-ts.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: lint-ts

on:
push:
avifenesh marked this conversation as resolved.
Show resolved Hide resolved
branches: ["main"]
Expand All @@ -16,30 +17,23 @@ on:

env:
CARGO_TERM_COLOR: always

jobs:
job:
lint:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4

- uses: ./.github/workflows/lint-ts
with:
package-folder: ./node
name: lint node

- uses: ./.github/workflows/lint-ts
with:
package-folder: ./benchmarks/node
name: lint benchmark
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: ./.github/workflows/lint-ts
with:
package-folder: ./benchmarks/utilities
name: lint benchmark utilities
- name: Install dependencies
run: |
npm install @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-tsdoc eslint typescript eslint-plugin-import@latest eslint-config-prettier prettier

- name: lint ts
- name: Run linting and prettier
run: |
npm install @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-tsdoc eslint typescript eslint-plugin-import@latest eslint-config-prettier
npm i
npx eslint .
for folder in node benchmarks/node benchmarks/utilities; do
npx eslint ${{ github.workspace }}/$folder
npx prettier --check ${{ github.workspace }}/$folder
done
44 changes: 22 additions & 22 deletions benchmarks/node/node_benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function redisBenchmark(
clients: IAsyncClient[],
totalCommands: number,
data: string,
actionLatencies: Record<ChosenAction, number[]>
actionLatencies: Record<ChosenAction, number[]>,
) {
while (startedTasksCounter < totalCommands) {
startedTasksCounter += 1;
Expand Down Expand Up @@ -97,14 +97,14 @@ async function createBenchTasks(
totalCommands: number,
numOfConcurrentTasks: number,
data: string,
actionLatencies: Record<ChosenAction, number[]>
actionLatencies: Record<ChosenAction, number[]>,
) {
startedTasksCounter = 0;
const tic = process.hrtime();

for (let i = 0; i < numOfConcurrentTasks; i++) {
runningTasks.push(
redisBenchmark(clients, totalCommands, data, actionLatencies)
redisBenchmark(clients, totalCommands, data, actionLatencies),
);
}

Expand All @@ -115,7 +115,7 @@ async function createBenchTasks(

function latencyResults(
prefix: string,
latencies: number[]
latencies: number[],
): Record<string, number> {
const result: Record<string, number> = {};
result[prefix + "_p50_latency"] = calculateLatency(latencies, 50);
Expand All @@ -136,13 +136,13 @@ async function runClients(
dataSize: number,
data: string,
clientDisposal: (client: IAsyncClient) => void,
isCluster: boolean
isCluster: boolean,
) {
const now = new Date();
console.log(
`Starting ${clientName} data size: ${dataSize} concurrency: ${numOfConcurrentTasks} client count: ${
clients.length
} isCluster: ${isCluster} ${now.toLocaleTimeString()}`
} isCluster: ${isCluster} ${now.toLocaleTimeString()}`,
);
const actionLatencies = {
[ChosenAction.SET]: [],
Expand All @@ -155,21 +155,21 @@ async function runClients(
totalCommands,
numOfConcurrentTasks,
data,
actionLatencies
actionLatencies,
);
const tps = Math.round(startedTasksCounter / time);

const getNonExistingLatencies =
actionLatencies[ChosenAction.GET_NON_EXISTING];
const getNonExistingLatencyResults = latencyResults(
"get_non_existing",
getNonExistingLatencies
getNonExistingLatencies,
);

const getExistingLatencies = actionLatencies[ChosenAction.GET_EXISTING];
const getExistingLatencyResults = latencyResults(
"get_existing",
getExistingLatencies
getExistingLatencies,
);

const setLatencies = actionLatencies[ChosenAction.SET];
Expand All @@ -193,10 +193,10 @@ async function runClients(

function createClients(
clientCount: number,
createAction: () => Promise<IAsyncClient>
createAction: () => Promise<IAsyncClient>,
): Promise<IAsyncClient[]> {
const creationActions = Array.from({ length: clientCount }, () =>
createAction()
createAction(),
);
return Promise.all(creationActions);
}
Expand All @@ -210,7 +210,7 @@ async function main(
clientCount: number,
useTLS: boolean,
clusterModeEnabled: boolean,
port: number
port: number,
) {
const data = generateValue(dataSize);

Expand All @@ -222,7 +222,7 @@ async function main(
clientClass.createClient({
addresses: [{ host, port }],
useTLS,
})
}),
);
await runClients(
clients,
Expand All @@ -234,7 +234,7 @@ async function main(
(client) => {
(client as RedisClient).close();
},
clusterModeEnabled
clusterModeEnabled,
);
await new Promise((resolve) => setTimeout(resolve, 100));
}
Expand Down Expand Up @@ -268,7 +268,7 @@ async function main(
(client) => {
(client as RedisClientType).disconnect();
},
clusterModeEnabled
clusterModeEnabled,
);
await new Promise((resolve) => setTimeout(resolve, 100));

Expand Down Expand Up @@ -297,7 +297,7 @@ async function main(
(client) => {
(client as RedisClientType).disconnect();
},
clusterModeEnabled
clusterModeEnabled,
);
}
}
Expand All @@ -313,20 +313,20 @@ Promise.resolve() // just added to clean the indentation of the rest of the call
const clientCount: string[] = receivedOptions.clientCount;
const lambda: (
numOfClients: string,
concurrentTasks: string
concurrentTasks: string,
) => [number, number, number] = (
numOfClients: string,
concurrentTasks: string
concurrentTasks: string,
) => [parseInt(concurrentTasks), dataSize, parseInt(numOfClients)];
const product: [number, number, number][] = concurrentTasks
.flatMap((concurrentTasks: string) =>
clientCount.map((clientCount) =>
lambda(clientCount, concurrentTasks)
)
lambda(clientCount, concurrentTasks),
),
)
.filter(
([concurrentTasks, , clientCount]) =>
clientCount <= concurrentTasks
clientCount <= concurrentTasks,
);

for (const [concurrentTasks, dataSize, clientCount] of product) {
Expand All @@ -342,7 +342,7 @@ Promise.resolve() // just added to clean the indentation of the rest of the call
clientCount,
receivedOptions.tls,
receivedOptions.clusterModeEnabled,
receivedOptions.port
receivedOptions.port,
);
}

Expand Down
6 changes: 4 additions & 2 deletions benchmarks/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"description": "",
"main": "node_benchmark.ts",
"scripts": {
"bench": "node node_benchmark.js"
"bench": "node node_benchmark.js",
"prettier:check:ci": "./node_modules/.bin/prettier --check .",
"prettier:format": "./node_modules/.bin/prettier --write . "
},
"author": "",
"license": "ISC",
Expand All @@ -20,7 +22,7 @@
},
"devDependencies": {
"@types/node": "^18.7.9",
"prettier": "^2.7.1",
"prettier": "^2.8.8",
"typescript": "^4.8.4"
}
}
Loading
Loading