This repository was archived by the owner on Aug 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathindex.js
More file actions
349 lines (294 loc) · 8.31 KB
/
index.js
File metadata and controls
349 lines (294 loc) · 8.31 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
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
'use strict'
const thunk = require('thunks')()
const redis = require('..')
const nodeRedis = require('redis')
const IoRedis = require('ioredis')
// const co = require('co')
// test in thunks(thunk base)
thunk(bench)(console.log.bind(console))
// // test in co(promise base)
// co(bench)
// .then(console.log.bind(console))
// .catch(console.error.bind(console))
function * bench () {
let timeN = 0
let timeT = 0
let timeI = 0
const testLen = 100000
const titleN = 'redis(N):'
const titleT = 'redis(T):'
const titleI = 'redis(I):'
const clientN = nodeRedis.createClient(6380)
const clientT = redis.createClient(6381)
const clientI = new IoRedis(6382)
const queue = []
while (queue.length < testLen) queue.push(queue.length)
const smallStr = 'teambition'
const longStr = (new Array(4097).join('-'))
function printResult (title, timeN, timeT, timeI) {
console.log(`\n${title}:`)
console.log(titleN, `${timeN}ms`, Math.floor(testLen * 1000 / timeN) + 'ops/sec', '100%')
console.log(titleT, `${timeT}ms`, Math.floor(testLen * 1000 / timeT) + 'ops/sec', ((timeN / timeT) * 100).toFixed(1) + '%')
console.log(titleI, `${timeI}ms`, Math.floor(testLen * 1000 / timeI) + 'ops/sec', ((timeN / timeI) * 100).toFixed(1) + '%')
}
console.log(titleN + 'node_redis ', yield function (done) { clientN.flushdb(done) })
console.log(titleT + 'thunk-redis ', yield clientT.flushdb())
console.log(titleI + 'ioRedis ', yield clientI.flushdb())
console.log(`Bench start:(${testLen})\n`)
// PING concurrency(full thread)
yield thunk.delay(100)
timeN = Date.now()
yield queue.map(function () {
return function (done) { clientN.ping(done) }
})
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
yield queue.map(function () {
return clientT.ping()
})
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
yield queue.map(function () {
return clientI.ping()
})
timeI = Date.now() - timeI
printResult('PING concurrency(full thread)', timeN, timeT, timeI)
// PING concurrency(1000 thread)
yield thunk.delay(100)
timeN = Date.now()
yield function * () {
let count = queue.length
yield queue.slice(0, 1000).map(function () {
return next
})
function next (callback) {
if (count > 0) {
count--
clientN.ping(function (err) {
if (!err) next(callback)
else callback(err)
})
} else callback()
}
}
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
yield function * () {
let count = queue.length
yield queue.slice(0, 1000).map(function () {
return next
})
function next (callback) {
if (count > 0) {
count--
clientT.ping()(function (err) {
if (!err) next(callback)
else callback(err)
})
} else callback()
}
}
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
yield function * () {
let count = queue.length
yield queue.slice(0, 1000).map(function () {
return next
})
function next (callback) {
if (count > 0) {
count--
clientI.ping()
.then(function () {
next(callback)
})
.catch(callback)
} else callback()
}
}
timeI = Date.now() - timeI
printResult('PING concurrency(1000 thread)', timeN, timeT, timeI)
// PING sequential 1 by 1
yield thunk.delay(100)
timeN = Date.now()
for (let i = queue.length; i > 0; i--) {
yield function (done) { clientN.ping(done) }
}
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
for (let i = queue.length; i > 0; i--) {
yield clientT.ping()
}
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
for (let i = queue.length; i > 0; i--) {
yield clientI.ping()
}
timeI = Date.now() - timeI
printResult('PING sequential 1 by 1', timeN, timeT, timeI)
// SET small string
yield thunk.delay(100)
timeN = Date.now()
yield queue.map(function () {
return function (done) { clientN.set('zensh_thunks_00000001', smallStr, done) }
})
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
yield queue.map(function () {
return clientT.set('zensh_thunks_00000001', smallStr)
})
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
yield queue.map(function () {
return clientI.set('zensh_thunks_00000001', smallStr)
})
timeI = Date.now() - timeI
printResult('SET small string', timeN, timeT, timeI)
// GET small string
yield thunk.delay(100)
timeN = Date.now()
yield queue.map(function () {
return function (done) { clientN.get('zensh_thunks_00000001', done) }
})
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
yield queue.map(function () {
return clientT.get('zensh_thunks_00000001')
})
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
yield queue.map(function () {
return clientI.get('zensh_thunks_00000001')
})
timeI = Date.now() - timeI
printResult('GET small string', timeN, timeT, timeI)
// SET long string
yield thunk.delay(100)
timeN = Date.now()
yield queue.map(function () {
return function (done) { clientN.set('zensh_thunks_00000002', longStr, done) }
})
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
yield queue.map(function () {
return clientT.set('zensh_thunks_00000002', longStr)
})
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
yield queue.map(function () {
return clientI.set('zensh_thunks_00000002', longStr)
})
timeI = Date.now() - timeI
printResult('SET long string', timeN, timeT, timeI)
// GET long string
yield thunk.delay(100)
timeN = Date.now()
yield queue.map(function () {
return function (done) { clientN.get('zensh_thunks_00000002', done) }
})
timeN = Date.now() - timeN
yield thunk.delay(100)
timeT = Date.now()
yield queue.map(function () {
return clientT.get('zensh_thunks_00000002')
})
timeT = Date.now() - timeT
yield thunk.delay(100)
timeI = Date.now()
yield queue.map(function () {
return clientI.get('zensh_thunks_00000002')
})
timeI = Date.now() - timeI
printResult('GET long string', timeN, timeT, timeI)
// // INCR
// yield thunk.delay(100)
//
// timeN = Date.now()
// yield queue.map(function () {
// return function (done) { clientN.incr('zensh_thunks_00000003', done) }
// })
// timeN = Date.now() - timeN
//
// yield thunk.delay(100)
//
// timeT = Date.now()
// yield queue.map(function () {
// return clientT.incr('zensh_thunks_00000003')
// })
// timeT = Date.now() - timeT
//
// yield thunk.delay(100)
//
// timeI = Date.now()
// yield queue.map(function () {
// return clientI.incr('zensh_thunks_00000003')
// })
// timeI = Date.now() - timeI
// printResult('INCR', timeN, timeT, timeI)
//
// // LPUSH
// yield thunk.delay(100)
//
// timeN = Date.now()
// yield queue.map(function () {
// return function (done) { clientN.lpush('zensh_thunks_00000004', smallStr, done) }
// })
// timeN = Date.now() - timeN
//
// yield thunk.delay(100)
//
// timeT = Date.now()
// yield queue.map(function () {
// return clientT.lpush('zensh_thunks_00000004', smallStr)
// })
// timeT = Date.now() - timeT
//
// yield thunk.delay(100)
//
// timeI = Date.now()
// yield queue.map(function () {
// return clientI.lpush('zensh_thunks_00000004', smallStr)
// })
// timeI = Date.now() - timeI
// printResult('LPUSH', timeN, timeT, timeI)
//
// // LRANGE
// yield thunk.delay(100)
//
// timeN = Date.now()
// yield queue.map(function () {
// return function (done) { clientN.lrange('zensh_thunks_00000004', '0', '100', done) }
// })
// timeN = Date.now() - timeN
//
// yield thunk.delay(100)
//
// timeT = Date.now()
// yield queue.map(function () {
// return clientT.lrange('zensh_thunks_00000004', '0', '100')
// })
// timeT = Date.now() - timeT
//
// yield thunk.delay(100)
//
// timeI = Date.now()
// yield queue.map(function () {
// return clientI.lrange('zensh_thunks_00000004', '0', '100')
// })
// timeI = Date.now() - timeI
// printResult('LRANGE 100', timeN, timeT, timeI)
yield thunk.delay(100)
process.exit()
}