Skip to content

Commit 151776f

Browse files
authored
Multi tenant beta (#11)
* native search facets async * refactoring tests for index_path * passed all old tests with refactored multi tenant * change db directory path to "data" * list indexes | crud tests for itemsjs * search benchmark | simple multitenancy test * async searching | closing properly lmdb connection * sorting in each separate index * bench * 2.1 version
1 parent 09c0d85 commit 151776f

25 files changed

+1520
-1753
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ temp/
4141
flightplan.js
4242
build/
4343
*.mdb/
44+
imdb.json
45+
imdb2.json

bench/benchmark.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const storage = require('./../src/storage');
5+
const addon = require('./../src/addon');
6+
const Facets = require('./../src/facets');
7+
//const data = require('./fixtures/items.json');
8+
const _ = require('lodash');
9+
const Promise = require('bluebird');
10+
11+
var facets = new Facets();
12+
13+
14+
var config = {
15+
aggregations: {
16+
year: {
17+
size: 10,
18+
conjunction: true
19+
},
20+
genres: {
21+
size: 10,
22+
conjunction: false
23+
},
24+
tags: {
25+
size: 10,
26+
conjunction: true
27+
},
28+
country: {
29+
size: 10,
30+
conjunction: true
31+
}
32+
}
33+
}
34+
35+
var input = {
36+
filters: {
37+
tags: ['prison']
38+
//genres: ['Action']
39+
}
40+
}
41+
42+
var filters_array = _.map(input.filters, function(filter, key) {
43+
return {
44+
key: key,
45+
values: filter,
46+
conjunction: config.aggregations[key].conjunction !== false
47+
}
48+
})
49+
50+
filters_array.sort(function(a, b) {
51+
return a.conjunction > b.conjunction ? 1 : -1;
52+
})
53+
54+
var facets_fields = Object.keys(config.aggregations);
55+
56+
(async function() {
57+
58+
for (var i = 0 ; i < 10 ; ++i) {
59+
60+
var index = storage.index({
61+
json_path: './imdb.json',
62+
index_path: './data/db_' + i + '.mdb',
63+
faceted_fields: ['actors', 'genres', 'year', 'tags'],
64+
append: false
65+
});
66+
}
67+
68+
var time = new Date().getTime();
69+
70+
// 1000 req in 700 ms
71+
// 1428 req / s
72+
await Promise.all(_.range(0, 1000, 1))
73+
.map(async i => {
74+
75+
var number = i % 10;
76+
await addon.search_facets_async({
77+
input: input,
78+
filters_array: filters_array,
79+
aggregations: config.aggregations,
80+
facets_fields, facets_fields,
81+
query_ids: null,
82+
index_path: './data/db_' + number + '.mdb'
83+
})
84+
.then(res => {
85+
//console.log('res')
86+
//console.log(res)
87+
})
88+
.catch(res => {
89+
//console.log('catch')
90+
//console.log(res)
91+
});
92+
93+
94+
}, {
95+
concurrency: 10
96+
})
97+
98+
console.log(`bench: ${new Date().getTime() - time}`);
99+
100+
var time = new Date().getTime();
101+
var number = i % 10;
102+
103+
addon.search_facets({
104+
input: input,
105+
filters_array: filters_array,
106+
aggregations: config.aggregations,
107+
facets_fields, facets_fields,
108+
query_ids: null,
109+
index_path: './data/db_' + number + '.mdb'
110+
})
111+
112+
console.log(`bench: ${new Date().getTime() - time}`);
113+
114+
})();

bench/benchmark_2.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const storage = require('./../src/storage');
5+
const addon = require('./../src/addon');
6+
const itemsjs = require('./../src/index')();
7+
const _ = require('lodash');
8+
const Promise = require('bluebird');
9+
const Facets = require('./../src/facets');
10+
const facets = new Facets();
11+
12+
var config = {
13+
aggregations: {
14+
year: {
15+
size: 10,
16+
conjunction: true
17+
},
18+
genres: {
19+
size: 10,
20+
conjunction: false
21+
},
22+
tags: {
23+
size: 10,
24+
conjunction: true
25+
},
26+
country: {
27+
size: 10,
28+
conjunction: true
29+
}
30+
}
31+
}
32+
33+
var input = {
34+
filters: {
35+
tags: ['prison']
36+
//genres: ['Action']
37+
}
38+
};
39+
40+
var filters_array = _.map(input.filters, function(filter, key) {
41+
return {
42+
key: key,
43+
values: filter,
44+
conjunction: config.aggregations[key].conjunction !== false
45+
}
46+
})
47+
48+
filters_array.sort(function(a, b) {
49+
return a.conjunction > b.conjunction ? 1 : -1;
50+
})
51+
52+
var facets_fields = Object.keys(config.aggregations);
53+
54+
(async function() {
55+
56+
for (var i = 0 ; i < 100 ; ++i) {
57+
58+
var index = await itemsjs.index('db_' + i, {
59+
json_path: './imdb2.json',
60+
append: false,
61+
configuration: config
62+
});
63+
}
64+
65+
var time = new Date().getTime();
66+
67+
// 1000 req in 700 ms
68+
// 1428 req / s
69+
await Promise.all(_.range(0, 100, 1))
70+
.map(async i => {
71+
72+
var number = i % 10;
73+
74+
/*await addon.search_facets_async({
75+
input: input,
76+
filters_array: filters_array,
77+
aggregations: config.aggregations,
78+
facets_fields, facets_fields,
79+
query_ids: null,
80+
index_path: './data/db_' + number + '.mdb'
81+
})*/
82+
83+
/*await facets.search_native('./data/db_' + number + '.mdb', input, {
84+
is_async: true
85+
})*/
86+
87+
await itemsjs.search('db_' + number, input, {
88+
//is_async: true
89+
})
90+
.then(res => {
91+
//console.log('res')
92+
//console.log(res)
93+
})
94+
.catch(res => {
95+
//console.log('catch')
96+
console.log(res)
97+
});
98+
}, {
99+
concurrency: 10
100+
})
101+
102+
console.log(`bench: ${new Date().getTime() - time}`);
103+
104+
var time = new Date().getTime();
105+
106+
/*for (var i = 0 ; i < 1000 ; ++i) {
107+
108+
var number = i % 10;
109+
addon.search_facets({
110+
input: input,
111+
filters_array: filters_array,
112+
aggregations: config.aggregations,
113+
facets_fields, facets_fields,
114+
query_ids: null,
115+
index_path: './data/db_' + number + '.mdb'
116+
})
117+
}*/
118+
119+
console.log(`bench: ${new Date().getTime() - time}`);
120+
121+
})();

0 commit comments

Comments
 (0)