예제 #1
0
// TestMain is the testing entrypoint.
func TestMain(m *testing.M) {
	config := spiffy.NewDbConnectionFromEnvironment()
	spiffy.CreateDbAlias("main", config)
	spiffy.SetDefaultAlias("main")

	os.Exit(m.Run())
}
예제 #2
0
파일: main.go 프로젝트: blendlabs/spiffy
func main() {
	err := spiffy.SetDefaultDb(spiffy.NewDbConnectionFromEnvironment())
	if err != nil {
		log.Fatal(err)
	}

	m := migration.New(
		"create & fill `test_vocab`",
		migration.New(
			"create `test_vocab` table",
			migration.Step(
				migration.CreateTable,
				migration.Body(
					"CREATE TABLE test_vocab (id serial not null, word varchar(32) not null);",
					"ALTER TABLE test_vocab ADD CONSTRAINT pk_test_vocab_id PRIMARY KEY(id);",
				),
				"test_vocab",
			),
		),
		migration.New(
			"fill `test_vocab`",
			migration.ReadDataFile("data.sql"),
		),
		migration.New(
			"drop `test_vocab` table",
			migration.Step(
				migration.AlterTable,
				migration.Body(
					"DROP TABLE test_vocab;",
				),
				"test_vocab",
			),
		),
	)
	m.SetLogger(migration.NewLogger())
	m.SetShouldAbortOnError(true)
	err = m.Apply(spiffy.DefaultDb())
	if err != nil {
		log.Fatal(err)
	}
}
예제 #3
0
파일: main.go 프로젝트: blendlabs/spiffy
func main() {
	err := spiffy.SetDefaultDb(spiffy.NewDbConnectionFromEnvironment())
	if err != nil {
		log.Fatal(err)
	}

	err = createTable()
	if err != nil {
		log.Fatal(err)
	}

	defer dropTable()

	err = seedObjects(createCount)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Finished seeding objects, starting load test.")

	// do spiffy query
	uncached := spiffy.NewDbConnectionFromEnvironment()
	uncached.DisableStatementCache()
	_, err = uncached.Open()
	if err != nil {
		log.Fatal(err)
	}

	spiffyStart := time.Now()
	spiffyTimings, err := benchHarness(uncached, threadCount, selectCount, spiffyAccess)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Spiffy Elapsed: %v\n", time.Since(spiffyStart))

	// do spiffy query
	cached := spiffy.NewDbConnectionFromEnvironment()
	cached.EnableStatementCache()
	_, err = cached.Open()
	if err != nil {
		log.Fatal(err)
	}

	spiffyCachedStart := time.Now()
	spiffyCachedTimings, err := benchHarness(cached, threadCount, selectCount, spiffyAccess)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Spiffy (Statement Cache) Elapsed: %v\n", time.Since(spiffyCachedStart))

	// do baseline query
	baselineStart := time.Now()
	baseline := spiffy.NewDbConnectionFromEnvironment()
	_, err = baseline.Open()
	if err != nil {
		log.Fatal(err)
	}

	baselineTimings, err := benchHarness(baseline, threadCount, selectCount, baselineAccess)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Baseline Elapsed: %v\n", time.Since(baselineStart))

	println()

	fmt.Println("Timings Aggregates:")
	fmt.Printf("\tAvg Baseline                 : %v\n", util.Math.MeanOfDuration(baselineTimings))
	fmt.Printf("\tAvg Spiffy                   : %v\n", util.Math.MeanOfDuration(spiffyTimings))
	fmt.Printf("\tAvg Spiffy (Statement Cache) : %v\n", util.Math.MeanOfDuration(spiffyCachedTimings))

	println()

	fmt.Printf("\t99th Baseline                 : %v\n", util.Math.PercentileOfDuration(baselineTimings, 99.0))
	fmt.Printf("\t99th Spiffy                   : %v\n", util.Math.PercentileOfDuration(spiffyTimings, 99.0))
	fmt.Printf("\t99th Spiffy (Statement Cache) : %v\n", util.Math.PercentileOfDuration(spiffyCachedTimings, 99.0))
}