-
Notifications
You must be signed in to change notification settings - Fork 1
/
catpaths.go
246 lines (225 loc) · 4.44 KB
/
catpaths.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
package main
import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"math/rand"
"net/http"
"sync"
"time"
"github.com/chilts/sid"
"github.com/tarantool/go-tarantool"
)
var names = []string{
"Боня",
"Ася",
"Алиса",
"Багира",
"Бусинка",
"Буся",
"Аврора",
"Муся",
"Агния",
"Ева",
"Мася",
"Агата",
"Василиса",
"Соня",
"Агаша",
"Мурка",
"Муська",
"Нюша",
"Бася",
"Симка",
"Абракадабра",
"Ангел",
"Багирка",
"Аба",
"Анабель",
"Абби",
"Сима",
"Ванесса",
"Адель",
"Дымка",
"Абигель",
"Бакси",
"Барселона",
"Масяня",
"Абалина",
"Даша",
"Гера",
"Агнесса",
"Альфа",
"Бэлла",
"Амели",
"Джессика",
"Айса",
"Барса",
"Карамелька",
"Бан-Ши",
"Джесси",
"Ириска",
"Китти",
"Агнес",
"Айрис",
"Кака",
"Барсик",
"Боня",
"Бакс",
"Алекс",
"Бади",
"Амур",
"Ебони",
"Абуссель",
"Баксик",
"Жопкинс",
"Кузя",
"Персик",
"Абрек",
"Абрикос",
"Тимоша",
"Авалон",
"Бабник",
"Саймон",
"Бурбузяка",
"Абу",
"Марсик",
"Маркиз",
"Дымок",
"Лаки",
"Симба",
"Абрамович",
"Сёма",
"Пушок",
"Айс",
"Бося",
"Алмаз",
"Кекс",
"Басик",
"Макс",
"Феликс",
"Гарфилд",
"Том",
"Тиша",
"Цезарь",
"Тишка",
"Мася",
"Абакан",
"Лакки",
"Васька",
"Адольф",
"Марсель",
"Бабасик",
"Вася",
"Зевс",
"Вольт",
"Адидас",
"Лео",
}
func randName() string {
return names[rand.Intn(len(names))]
}
func randFloat(min float64, max float64) float64 {
return min + rand.Float64()*(max-min)
}
func main() {
opts := tarantool.Opts{User: "storage", Pass: "passw0rd"}
conn, err := tarantool.Connect("127.0.0.1:3301", opts)
if err != nil {
panic(err)
}
defer conn.Close()
conn.Call("box.space.geo:truncate", []interface{}{})
tr := &http.Transport{
MaxConnsPerHost: 50,
}
defer tr.CloseIdleConnections()
cl := &http.Client{
Transport: tr,
}
// Питерские координаты
bounds := []float64{298.02, 148.52, 299.64, 149.20}
centerx := 299.12
centery := 148.80
rand.Seed(time.Now().UnixNano())
data := make(map[string]map[string]interface{})
for i := 0; i < 1e3; i++ {
id := sid.IdHex()
item := map[string]interface{}{
"id": id,
"coordinates": []float64{randFloat(bounds[0], bounds[2]), randFloat(bounds[1], bounds[3])},
"name": randName(),
}
data[id] = item
bytes := new(bytes.Buffer)
json.NewEncoder(bytes).Encode(item)
resp, err := cl.Post("http://127.0.0.1:8080/put", "application/json", bytes)
if err != nil {
panic(err)
}
resp.Body.Close()
}
var wg sync.WaitGroup
parralel := 0
for step := 0; step < 1e6; step++ {
for _, source := range data {
value := make(map[string]interface{})
value["coordinates"] = source["coordinates"]
value["id"] = source["id"]
value["name"] = source["name"]
coords := value["coordinates"].([]float64)
parralel = parralel + 1
wg.Add(1)
go func() {
if rand.Int31n(4) == 0 {
coords[0] = coords[0] + 0.0003
} else {
coords[0] = coords[0] - 0.0003
}
if rand.Int31n(4) == 0 {
coords[1] = coords[1] + 0.0003
} else {
coords[1] = coords[1] - 0.0003
}
if coords[0] > centerx {
coords[0] = coords[0] - 0.0003
} else {
coords[0] = coords[0] + 0.0003
}
if coords[1] > centery {
coords[1] = coords[1] - 0.0003
} else {
coords[1] = coords[1] + 0.0003
}
if coords[0] < bounds[0] {
coords[0] = bounds[0]
}
if coords[0] > bounds[2] {
coords[0] = bounds[2]
}
if coords[1] < bounds[1] {
coords[1] = bounds[1]
}
if coords[1] > bounds[3] {
coords[1] = bounds[3]
}
value["coordinates"] = coords
bytes := new(bytes.Buffer)
json.NewEncoder(bytes).Encode(value)
resp, err := cl.Post("http://127.0.0.1:8080/put", "application/json", bytes)
if err != nil {
panic(err)
}
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
wg.Done()
}()
if parralel == 1 {
parralel = 0
wg.Wait()
}
}
time.Sleep(10 * time.Millisecond)
}
}