<commit_before>package main

import (
	"fmt"
	"github.com/gophergala2016/goad/lambda/sqsadaptor"
	"io/ioutil"
	"net/http"
	"os"
	"strconv"
	"sync"
	"time"
)

func main() {
	address := os.Args[1]
	concurrencycount, err := strconv.Atoi(os.Args[2])
	if err != nil {
		fmt.Printf("ERROR %s\n", err)
		return
	}
	requestcount, err := strconv.Atoi(os.Args[3])
	sqsurl := os.Args[4]
	if err != nil {
		fmt.Printf("ERROR %s\n", err)
		return
	}
	client := &http.Client{}
	fmt.Printf("Will spawn %d workers each making %d requests to %s\n", concurrencycount, requestcount, address)
	runLoadTest(client, sqsurl, address, requestcount, concurrencycount)
}

func runLoadTest(client *http.Client, sqsurl string, url string, requestcount int, concurrencycount int) {
	sqsAdaptor := sqsadaptor.NewDummyAdaptor(sqsurl)

	totalRequests := requestcount * concurrencycount
	ch := make(chan sqsadaptor.Result, totalRequests)
	var wg sync.WaitGroup
	for i := 0; i < concurrencycount; i++ {
		wg.Add(1)
		go fetch(client, url, requestcount, ch, &wg)
	}
	fmt.Println("Waiting for results…")

	completedRequests := 0
	for completedRequests < totalRequests {
		r := <-ch
		completedRequests++
		if completedRequests%10 == 0 {
			fmt.Printf("\r%.2f%% done (%d requests out of %d)", (float64(completedRequests)/float64(totalRequests))*100.0, completedRequests, totalRequests)
		}
		sqsAdaptor.SendResult(r)
	}
	wg.Wait()
	fmt.Printf("\nYay🎈\n")

}

func fetch(client *http.Client, address string, requestcount int, ch chan sqsadaptor.Result, wg *sync.WaitGroup) {
	defer wg.Done()
	fmt.Printf("Fetching %s %d times\n", address, requestcount)
	for i := 0; i < requestcount; i++ {
		start := time.Now()
		req, err := http.NewRequest("GET", address, nil)
		req.Header.Add("User-Agent", "GOAD/0.1")

		response, err := client.Do(req)
		if err != nil {
			fmt.Printf("ERROR %s\n", err)
			return
		}
		_, err = ioutil.ReadAll(response.Body)
		if err != nil {
			fmt.Printf("ERROR %s\n", err)
			return
		}
		elapsed := time.Since(start)
		result := sqsadaptor.Result{
			"2016-01-01 10:00:00",
			"example.com",
			"Fetch",
			"928429348",
			200,
			elapsed.Nanoseconds(),
			2398,
			"Finished",
		}
		ch <- result
	}

}<commit_msg>Put some real data into the result<commit_after>package main

import (
	"fmt"
	"github.com/gophergala2016/goad/lambda/sqsadaptor"
	"io/ioutil"
	"net/http"
	"os"
	"strconv"
	"sync"
	"time"
)

func main() {
	address := os.Args[1]
	concurrencycount, err := strconv.Atoi(os.Args[2])
	if err != nil {
		fmt.Printf("ERROR %s\n", err)
		return
	}
	requestcount, err := strconv.Atoi(os.Args[3])
	sqsurl := os.Args[4]
	if err != nil {
		fmt.Printf("ERROR %s\n", err)
		return
	}
	client := &http.Client{}
	fmt.Printf("Will spawn %d workers each making %d requests to %s\n", concurrencycount, requestcount, address)
	runLoadTest(client, sqsurl, address, requestcount, concurrencycount)
}

func runLoadTest(client *http.Client, sqsurl string, url string, requestcount int, concurrencycount int) {
	sqsAdaptor := sqsadaptor.NewDummyAdaptor(sqsurl)

	totalRequests := requestcount * concurrencycount
	ch := make(chan sqsadaptor.Result, totalRequests)
	var wg sync.WaitGroup
	for i := 0; i < concurrencycount; i++ {
		wg.Add(1)
		go fetch(client, url, requestcount, ch, &wg)
	}
	fmt.Println("Waiting for results…")

	completedRequests := 0
	for completedRequests < totalRequests {
		r := <-ch
		completedRequests++
		if completedRequests%10 == 0 {
			fmt.Printf("\r%.2f%% done (%d requests out of %d)", (float64(completedRequests)/float64(totalRequests))*100.0, completedRequests, totalRequests)
		}
		sqsAdaptor.SendResult(r)
	}
	wg.Wait()
	fmt.Printf("\nYay🎈\n")

}

func fetch(client *http.Client, address string, requestcount int, ch chan sqsadaptor.Result, wg *sync.WaitGroup) {
	defer wg.Done()
	fmt.Printf("Fetching %s %d times\n", address, requestcount)
	for i := 0; i < requestcount; i++ {
		start := time.Now()
		req, err := http.NewRequest("GET", address, nil)
		req.Header.Add("User-Agent", "GOAD/0.1")

		response, err := client.Do(req)
		if err != nil {
			fmt.Printf("ERROR %s\n", err)
			return
		}
		buf, err := ioutil.ReadAll(response.Body)
		if err != nil {
			fmt.Printf("ERROR %s\n", err)
			return
		}
		elapsed := time.Since(start)
		result := sqsadaptor.Result{
			start.Format(time.RFC3339),
			req.URL.Host,
			"Fetch",
			"4711",
			response.StatusCode,
			elapsed.Nanoseconds(),
			len(buf),
			"Finished",
		}
		ch <- result
	}

}
{'fraction_non_alphanumeric': 0.15763436024286034, 'fraction_numerical': 0.02023836294130875, 'mean_word_length': 4.043083900226757, 'pattern_counts': {'":': 0, '<': 13, '<?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': '6091937', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1726, 'n_words': 384}