-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
45 lines (36 loc) · 1.1 KB
/
main.go
File metadata and controls
45 lines (36 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"log"
"time"
"github.com/gocql/gocql"
"github.com/google/uuid"
)
func main() {
cluster := gocql.NewCluster("172.22.0.2")
cluster.Keyspace = "ks1"
cluster.Consistency = gocql.One
session, err := cluster.CreateSession()
if err != nil {
log.Fatalf("Failed to connect to ScyllaDB: %v", err)
}
defer session.Close()
query := `INSERT INTO impressions (impression_id, ad_id, image_url, click_url, impression_time)
VALUES (?, ?, ?, ?, ?)`
maxDuration := 1 * time.Second
startTime := time.Now()
count := 0
for time.Since(startTime) < maxDuration {
impressionID := uuid.New().String()
adID := "ad456"
imageURL := "https://example.com/image.jpg"
clickURL := "https://advertiser.com/click"
impressionTime := time.Now().UTC()
if err := session.Query(query, impressionID, adID, imageURL, clickURL, impressionTime).Exec(); err != nil {
log.Fatalf("Insert failed: %v", err)
}
count++
}
elapsed := time.Since(startTime)
fmt.Printf("Inserted %d rows in %.2f seconds (%.2f inserts/second)\n", count, elapsed.Seconds(), float64(count)/elapsed.Seconds())
}