Skip to content

Commit

Permalink
chore: add benchmark app
Browse files Browse the repository at this point in the history
  • Loading branch information
sam committed Jan 17, 2023
1 parent 762934d commit 7f85e18
Show file tree
Hide file tree
Showing 15 changed files with 1,073 additions and 73 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
lib/
node_modules/
sdk.generated.ts
.bundle
.bundle
*.tgz
cdk.out
10 changes: 10 additions & 0 deletions benchmark/functions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@benchmark/functions",
"version": "0.0.0",
"private": true,
"type": "module",
"dependencies": {
"itty-aws": "workspace:^",
"@aws-sdk/client-dynamodb": "^3.245.0"
}
}
19 changes: 19 additions & 0 deletions benchmark/functions/src/itty-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { AWS } from "itty-aws";

const client = new AWS.DynamoDB();

const TableName = process.env.TABLE_NAME!;

export async function handler() {
await client.putItem({
TableName,
Item: {
pk: {
S: "pk",
},
prop: {
S: "value",
},
},
});
}
21 changes: 21 additions & 0 deletions benchmark/functions/src/v2-lambda.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { DynamoDB } from "aws-sdk";

const client = new DynamoDB();

const TableName = process.env.TABLE_NAME!;

export async function handler() {
await client
.putItem({
TableName,
Item: {
pk: {
S: "pk",
},
prop: {
S: "value",
},
},
})
.promise();
}
21 changes: 21 additions & 0 deletions benchmark/functions/src/v3-lambda.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { DynamoDBClient, PutItemCommand } from "@aws-sdk/client-dynamodb";

const client = new DynamoDBClient({});

const TableName = process.env.TABLE_NAME!;

export async function handler() {
await client.send(
new PutItemCommand({
TableName,
Item: {
pk: {
S: "pk",
},
prop: {
S: "value",
},
},
})
);
}
8 changes: 8 additions & 0 deletions benchmark/functions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"exclude": ["lib", "node_modules"],
"compilerOptions": {
"outDir": "lib"
}
}
3 changes: 3 additions & 0 deletions benchmark/infra/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app": "ts-node ./src/index.ts"
}
21 changes: 21 additions & 0 deletions benchmark/infra/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@benchmark/infra",
"version": "0.0.0",
"private": true,
"scripts": {
"synth": "cdk synth",
"deploy": "cdk deploy",
"hotswap": "cdk deploy --hotswap"
},
"dependencies": {
"aws-cdk-lib": "^2.60.0",
"@benchmark/functions": "workspace:^"
},
"devDependencies": {
"@types/node": "^16",
"aws-cdk": "^2.60.0",
"constructs": "^10",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
}
}
64 changes: 64 additions & 0 deletions benchmark/infra/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
App,
aws_dynamodb,
aws_lambda,
aws_lambda_nodejs,
Stack,
} from "aws-cdk-lib";

const app = new App();

const stack = new Stack(app, "itty-benchmark");

const table = new aws_dynamodb.Table(stack, "Table", {
partitionKey: {
name: "pk",
type: aws_dynamodb.AttributeType.STRING,
},
billingMode: aws_dynamodb.BillingMode.PAY_PER_REQUEST,
});

const props = {
environment: {
TABLE_NAME: table.tableName,
},
memorySize: 512,
};

const ittyFunc = new aws_lambda_nodejs.NodejsFunction(stack, "IttyFunc", {
functionName: "benchmark-itty",
runtime: aws_lambda.Runtime.NODEJS_18_X,
entry: require.resolve("@benchmark/functions/lib/itty-handler"),
bundling: {
externalModules: ["@aws-sdk/*"],
},
...props,
});

const v3BundledFunc = new aws_lambda_nodejs.NodejsFunction(stack, "V3Bundled", {
functionName: "benchmark-v3-bundled",
runtime: aws_lambda.Runtime.NODEJS_18_X,
entry: require.resolve("@benchmark/functions/lib/itty-handler"),
bundling: {
externalModules: [],
},
...props,
});

const v3ExcludedFunc = new aws_lambda_nodejs.NodejsFunction(
stack,
"V3Excluded",
{
functionName: "benchmark-v3-excluded",
runtime: aws_lambda.Runtime.NODEJS_18_X,
entry: require.resolve("@benchmark/functions/lib/itty-handler"),
bundling: {
externalModules: ["@aws-sdk/*"],
},
...props,
}
);

table.grantReadWriteData(ittyFunc);
table.grantReadWriteData(v3BundledFunc);
table.grantReadWriteData(v3ExcludedFunc);
11 changes: 11 additions & 0 deletions benchmark/infra/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"exclude": ["lib", "node_modules"],
"compilerOptions": {
"outDir": "lib",
"module": "CommonJS",
"moduleResolution": "Node",
"target": "ES2022"
}
}
17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
{
"name": "itty-aws",
"version": "0.0.0",
"version": "0.0.1",
"files": [
"lib"
],
"type": "module",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"exports": {
".": {
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
}
},
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
"gen": "ts-node-esm ./scripts/gen-sdk-types.mts",
"build": "tsc -b",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"watch": "tsc -b -w",
"analyze:bundle": "sh ./scripts/analyze-bundle.sh"
"analyze:bundle": "sh ./scripts/analyze-bundle.sh",
"bench:synth": "pnpm -r --filter @benchmark/infra synth",
"bench:deploy": "pnpm -r --filter @benchmark/infra run deploy",
"bench:hotswap": "pnpm -r --filter @benchmark/infra run hotswap"
},
"dependencies": {
"aws-sdk": "2.1295.0"
Expand Down
Loading

0 comments on commit 7f85e18

Please sign in to comment.