Skip to content

Commit

Permalink
Merge branch 'master' into lambda-callback-update
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillip Edwards committed Jul 16, 2021
2 parents 4526389 + 70d1d08 commit 75adedb
Show file tree
Hide file tree
Showing 21 changed files with 752 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aws-ts-ecs-anywhere/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# ECS Anywhere

This example from our [ECS Anywhere launchblog post](httsp:https://pulumi.com/blog/ecs-anywhere-launch/) shows how to deploy an ECS cluster along with a dockerized app to Digital Ocean.
This example from our [ECS Anywhere launchblog post](https:https://pulumi.com/blog/ecs-anywhere-launch/) shows how to deploy an ECS cluster along with a dockerized app to Digital Ocean.

To do this, we use Pulumi infrastructure as code to provision an
[Elastic Container Service (ECS)](https://aws.amazon.com/ecs/) cluster, build our `Dockerfile` and deploy the
Expand Down
15 changes: 15 additions & 0 deletions misc/benchmarks/cs-many-resources/Dummy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Pulumi;

public class Dummy : ComponentResource
{
[Output]
public Output<string> Deadweight { get; private set; } = null!;

public Dummy(string name, Input<string> deadweight, ComponentResourceOptions? options = null)
: base("examples:dummy:Dummy", name, options)
{
this.Deadweight = deadweight;

this.RegisterOutputs();
}
}
41 changes: 41 additions & 0 deletions misc/benchmarks/cs-many-resources/MyStack.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.Immutable;

using Pulumi;

class MyStack : Stack
{
[Output]
public Output<int> ResourceCount { get; set; }

[Output]
public Output<int> ResourcePayloadBytes { get; set; }

public MyStack()
{
var config = new Config();
int resourceCount = config.RequireInt32("resource_count");
int resourcePayloadBytes = config.RequireInt32("resource_payload_bytes");

Output<int> resourcePayloadBytesOutput = Output.Create(resourcePayloadBytes);

for (var i = 0; i < resourceCount; i++) {
string deadweight = String.Concat(Enumerable.Repeat(
String.Format("{0:00000000}", i),
resourcePayloadBytes/8));
Dummy dummy = new Dummy($"dummy-{i}", deadweight);
resourcePayloadBytesOutput = dummy.Deadweight.Apply(w => w.Length);
}

this.ResourceCount = Output.Create(resourceCount);
this.ResourcePayloadBytes = resourcePayloadBytesOutput;
}

private static int GetEnv(string name, int defaultValue)
{
var v = System.Environment.GetEnvironmentVariable(name);
return v == null ? defaultValue : int.Parse(v);
}
}
7 changes: 7 additions & 0 deletions misc/benchmarks/cs-many-resources/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Threading.Tasks;
using Pulumi;

class Program
{
static Task<int> Main() => Deployment.RunAsync<MyStack>();
}
3 changes: 3 additions & 0 deletions misc/benchmarks/cs-many-resources/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: cs-many-resources
runtime: dotnet
description: A minimal C# Pulumi program
13 changes: 13 additions & 0 deletions misc/benchmarks/cs-many-resources/cs-many-resources.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pulumi" Version="3.*" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions misc/benchmarks/go-many-resources/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: go-many-resources
runtime: go
description: A benchmark to test performance of stacks with many resources
28 changes: 28 additions & 0 deletions misc/benchmarks/go-many-resources/dummy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

type Dummy struct {
pulumi.ResourceState

Deadweight pulumi.StringOutput `pulumi:"deadweight"`
}

type DummyArgs struct {
Deadweight pulumi.StringInput
}

func NewDummy(ctx *pulumi.Context, name string, args *DummyArgs, opts ...pulumi.ResourceOption) (*Dummy, error) {
dummy := &Dummy{}
err := ctx.RegisterComponentResource("examples:dummy:Dummy", name, dummy, opts...)
if err != nil {
return nil, err
}
dummy.Deadweight = args.Deadweight.ToStringOutput()
ctx.RegisterResourceOutputs(dummy, pulumi.Map{
"deadweight": dummy.Deadweight,
})
return dummy, nil
}
7 changes: 7 additions & 0 deletions misc/benchmarks/go-many-resources/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module go-many-resources

go 1.14

require (
github.com/pulumi/pulumi/sdk/v3 v3.6.1
)
431 changes: 431 additions & 0 deletions misc/benchmarks/go-many-resources/go.sum

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions misc/benchmarks/go-many-resources/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"fmt"
"strings"

"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)

func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
conf := config.New(ctx, "")
resourceCount := conf.RequireInt("resource_count")
resourcePayloadBytes := conf.RequireInt("resource_payload_bytes")

for i := 0; i < resourceCount; i++ {
deadweight := strings.Repeat(fmt.Sprintf("%08d", i), resourcePayloadBytes/8)

dummy, err := NewDummy(ctx, fmt.Sprintf("dummy-%d", i), &DummyArgs{
Deadweight: pulumi.String(deadweight),
})
if err != nil {
return err
}

if i == 0 {
ctx.Export("ResourcePayloadBytes", dummy.Deadweight.ApplyT(func(x string) int {
return len(x)
}))
}
}

ctx.Export("ResourceCount", pulumi.Int(resourceCount))
return nil
})
}
6 changes: 6 additions & 0 deletions misc/benchmarks/py-many-resources/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: py-many-resources
runtime:
name: python
options:
virtualenv: venv
description: A benchmark to test performance of stacks with many resources
17 changes: 17 additions & 0 deletions misc/benchmarks/py-many-resources/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
import pulumi

from dummy import Dummy

config = pulumi.Config();

resource_count = config.require_int('resource_count')
resource_payload_bytes = config.require_int('resource_payload_bytes')

for i in range(0, resource_count):
deadweight = '{:08}'.format(i) * int(resource_payload_bytes / 8)
dummy = Dummy(f'dummy-{i}', deadweight=deadweight)
if i == 0:
pulumi.export('ResourcePayloadBytes', dummy.deadweight.apply(lambda s: len(s)))

pulumi.export('ResourceCount', resource_count)
10 changes: 10 additions & 0 deletions misc/benchmarks/py-many-resources/dummy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pulumi


class Dummy(pulumi.ComponentResource):

def __init__(self, name, deadweight, opts=None):
super().__init__('examples:dummy:Dummy', name, {'deadweight': deadweight}, opts)

self.deadweight = pulumi.Output.from_input(deadweight)
self.register_outputs({'deadweight': self.deadweight})
1 change: 1 addition & 0 deletions misc/benchmarks/py-many-resources/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pulumi>=3.0.0,<4.0.0
3 changes: 3 additions & 0 deletions misc/benchmarks/ts-many-resources/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: ts-many-resources
runtime: nodejs
description: A minimal TypeScript Pulumi program
11 changes: 11 additions & 0 deletions misc/benchmarks/ts-many-resources/dummy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as pulumi from "@pulumi/pulumi";

export class Dummy extends pulumi.ComponentResource {
public deadweight: pulumi.Output<string>;

constructor(name: string, deadweight: pulumi.Input<string>, opts: pulumi.ComponentResourceOptions = {}) {
super("examples:dummy:Dummy", name, {'deadweight': deadweight}, opts);

this.deadweight = pulumi.Output.create(deadweight);
}
}
27 changes: 27 additions & 0 deletions misc/benchmarks/ts-many-resources/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as pulumi from "@pulumi/pulumi";

import { Dummy } from "./dummy";

const config = new pulumi.Config();

const resourceCount: number = config.requireNumber("resource_count");
const resourcePayloadBytes: number = config.requireNumber("resource_payload_bytes");

function pad8(num: number): string {
return ('00000000' + num).slice(-8);
}

function newDummy(i: number): Dummy {
const deadweight = pad8(i).repeat(resourcePayloadBytes/8);
return new Dummy(`dummy-${i}`, deadweight);
}

export const ResourceCount = resourceCount;

const dummy0 = newDummy(0);

export const ResourcePayloadBytes = dummy0.deadweight.apply(x => x.length);

for (var i = 1; i < resourceCount; i++) {
newDummy(i)
}
9 changes: 9 additions & 0 deletions misc/benchmarks/ts-many-resources/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "ts-many-resources",
"devDependencies": {
"@types/node": "^10.0.0"
},
"dependencies": {
"@pulumi/pulumi": "^3.0.0"
}
}
18 changes: 18 additions & 0 deletions misc/benchmarks/ts-many-resources/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"strict": true,
"outDir": "bin",
"target": "es2016",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.ts"
]
}
64 changes: 64 additions & 0 deletions misc/test/performance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package test

import (
"fmt"
"log"
"os"
"path"
Expand Down Expand Up @@ -99,6 +100,69 @@ func TestAccAwsPyS3Folder(t *testing.T) {
integration.ProgramTest(t, &test)
}

type manyResourcesConfig struct {
folder string
bench traces.Benchmark
resources int
payloadBytes int
}

func TestManyResources(t *testing.T) {
var configurations []manyResourcesConfig

for _, resources := range []int{64, 128, 256} {
confs := []manyResourcesConfig{
{
folder: "go-many-resources",
bench: bench(fmt.Sprintf("go-many-resources-%d", resources), "", "go", "go"),
resources: resources,
payloadBytes: 8,
},
{
folder: "cs-many-resources",
bench: bench(fmt.Sprintf("cs-many-resources-%d", resources), "", "dotnet", "csharp"),
resources: resources,
payloadBytes: 8,
},
{
folder: "ts-many-resources",
bench: bench(fmt.Sprintf("ts-many-resources-%d", resources), "", "nodejs", "typescript"),
resources: resources,
payloadBytes: 8,
},
{
folder: "py-many-resources",
bench: bench(fmt.Sprintf("py-many-resources-%d", resources), "", "python", "python"),
resources: resources,
payloadBytes: 8,
},
}
configurations = append(configurations, confs...)
}

check := func(t *testing.T, cfg manyResourcesConfig) {
opts := integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "..", "benchmarks", cfg.folder),
Config: map[string]string{
"resource_count": fmt.Sprintf("%d", cfg.resources),
"resource_payload_bytes": fmt.Sprintf("%d", cfg.payloadBytes),
},
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
assert.Equal(t, float64(cfg.resources), stack.Outputs["ResourceCount"])
assert.Equal(t, float64(cfg.payloadBytes), stack.Outputs["ResourcePayloadBytes"])
},
}
test := getBaseOptions(t).With(opts).With(cfg.bench.ProgramTestOptions())
integration.ProgramTest(t, &test)
}

for _, cfg := range configurations {
t.Run(cfg.bench.Name, func(t *testing.T) {
check(t, cfg)
})
}
}

func TestMain(m *testing.M) {
code := m.Run()

Expand Down

0 comments on commit 75adedb

Please sign in to comment.