<commit_before>package server

import (
	"fmt"
	"io/ioutil"
	"math/rand"
	"testing"

	"golang.org/x/sync/errgroup"

	"github.com/pachyderm/pachyderm/src/client"
	"github.com/pachyderm/pachyderm/src/client/pkg/require"
	"github.com/pachyderm/pachyderm/src/server/pkg/workload"
)

const (
	clients          = 6
	objectsPerClient = 100
	objectSize       = 1024 * 1024
)

func BenchmarkManyObjects(b *testing.B) {
	fmt.Println("running benchmark")
	b.Run("Put", func(b *testing.B) {
		for n := 0; n < b.N; n++ {
			var eg errgroup.Group
			for i := 0; i < clients; i++ {
				c := getPachClientInCluster(b)
				rand := rand.New(rand.NewSource(int64(i)))
				eg.Go(func() error {
					for j := 0; j < objectsPerClient; j++ {
						r := workload.NewReader(rand, objectSize)
						_, err := c.PutObject(r, fmt.Sprintf("%d%d%d", n, i, j))
						if err != nil {
							return err
						}
					}
					return nil
				})
			}
			b.SetBytes(clients * objectsPerClient * objectSize)
			require.NoError(b, eg.Wait())
		}
	})
	b.Run("Get", func(b *testing.B) {
		for n := 0; n < b.N; n++ {
			var eg errgroup.Group
			for i := 0; i < clients; i++ {
				c := getPachClientInCluster(b)
				eg.Go(func() error {
					for j := 0; j < objectsPerClient; j++ {
						err := c.GetTag(fmt.Sprintf("%d%d%d", n, i, j), ioutil.Discard)
						if err != nil {
							return err
						}
					}
					return nil
				})
			}
			b.SetBytes(clients * objectsPerClient * objectSize)
			require.NoError(b, eg.Wait())
		}
	})
	b.Run("CacheGet", func(b *testing.B) {
		for n := 0; n < b.N; n++ {
			var eg errgroup.Group
			for i := 0; i < clients; i++ {
				c := getPachClientInCluster(b)
				eg.Go(func() error {
					for j := 0; j < objectsPerClient; j++ {
						err := c.GetTag(fmt.Sprintf("%d%d%d", n, i, j), ioutil.Discard)
						if err != nil {
							return err
						}<commit_msg>Fix a bug in benchmarks.<commit_after>package server

import (
	"fmt"
	"io/ioutil"
	"math/rand"
	"testing"

	"golang.org/x/sync/errgroup"

	"github.com/pachyderm/pachyderm/src/client"
	"github.com/pachyderm/pachyderm/src/client/pkg/require"
	"github.com/pachyderm/pachyderm/src/server/pkg/workload"
)

const (
	clients          = 6
	objectsPerClient = 100
	objectSize       = 1024 * 1024
)

func BenchmarkManyObjects(b *testing.B) {
	fmt.Println("running benchmark")
	b.Run("Put", func(b *testing.B) {
		for n := 0; n < b.N; n++ {
			var eg errgroup.Group
			for i := 0; i < clients; i++ {
				c := getPachClientInCluster(b)
				rand := rand.New(rand.NewSource(int64(i)))
				eg.Go(func() error {
					for j := 0; j < objectsPerClient; j++ {
						r := workload.NewReader(rand, objectSize)
						if n == 0 {
							if _, err := c.PutObject(r, fmt.Sprintf("%d%d", i, j)); err != nil {
								return err
							}
						} else {
							if _, err := c.PutObject(r); err != nil {
								return err
							}
						}
					}
					return nil
				})
			}
			b.SetBytes(clients * objectsPerClient * objectSize)
			require.NoError(b, eg.Wait())
		}
	})
	b.Run("Get", func(b *testing.B) {
		for n := 0; n < b.N; n++ {
			var eg errgroup.Group
			for i := 0; i < clients; i++ {
				c := getPachClientInCluster(b)
				eg.Go(func() error {
					for j := 0; j < objectsPerClient; j++ {
						err := c.GetTag(fmt.Sprintf("%d%d", i, j), ioutil.Discard)
						if err != nil {
							return err
						}
					}
					return nil
				})
			}
			b.SetBytes(clients * objectsPerClient * objectSize)
			require.NoError(b, eg.Wait())
		}
	})
	b.Run("CacheGet", func(b *testing.B) {
		for n := 0; n < b.N; n++ {
			var eg errgroup.Group
			for i := 0; i < clients; i++ {
				c := getPachClientInCluster(b)
				eg.Go(func() error {
					for j := 0; j < objectsPerClient; j++ {
						err := c.GetTag(fmt.Sprintf("%d%d", i, j), ioutil.Discard)
						if err != nil {
							return err
						}
{'fraction_non_alphanumeric': 0.16990546218487396, 'fraction_numerical': 0.012342436974789915, 'mean_word_length': 2.413082437275986, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6190870', 'n_tokens_mistral': 1896, 'n_tokens_neox': 1486, 'n_words': 332}