Skip to content

Disable optimisations for benchmarking #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
1 change: 0 additions & 1 deletion server/metadata/get_metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const client = require('../esclient');
const types = require('../types');

function process_results(results) {
console.log(results)
var new_results = results.body["_source"]

// Add some metadata to the metadata
Expand Down
12 changes: 8 additions & 4 deletions server/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ function search(q, type, page, pageSize, preference) {
body,
size: pageSize,
from: page * pageSize,
timeout: '300ms', // This is more of a fallback/dirty workaround.
max_concurrent_shard_requests: 40,
pre_filter_shard_size: 2048,

// Optimizations
// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-shard-routing.html#shard-and-node-preference
preference: preference,
max_concurrent_shard_requests: 24, // Defines the number of concurrent shard requests per node this search executes concurrently. This value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests. Defaults to 5.
pre_filter_shard_size: 2048,
preference: '_local',
// timeout: '800ms', // Specifies the period of time to wait for a response from each shard. If no response is received before the timeout expires, the request fails and returns an error.
// allow_partial_search_results: true, // If true, returns partial results if there are shard request timeouts or shard failures. If false, returns an error with no partial results.
// ignore_unavailable: true, // If false, the request returns an error if it targets a missing or closed index.
});
}

Expand Down
29 changes: 15 additions & 14 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ const cidValidator = require('./metadata/cid_validator');
const app = express();
const port = 9615;

function error(res, code, err) {
console.error(`${code}: ${err}`);
console.trace(err);
function error(req, res, code, err) {
console.error(`${req.url} ${code}: ${err}`);

// Unwrap ES errors.
if (typeof err === 'object' && 'body' in err && 'error' in err.body) {
console.trace(err.body.error);
err = err.body.error;
}

if (process.env.NODE_ENV === 'production') {
// Don't leak production errors
err = 'Internal Server Error'
} else {
console.trace(err);
}

res.status(code).json({ error: `${err}` }).end();
Expand All @@ -27,7 +33,7 @@ app.get('/search', (req, res, next) => {
const pageSize = 15;

if (!('q' in req.query)) {
error(res, 400, 'query argument missing');
error(req, res, 400, 'query argument missing');
}

let page = 0;
Expand All @@ -37,14 +43,14 @@ app.get('/search', (req, res, next) => {

// For performance reasons, don't allow paging too far down
if (page > maxPage) {
error(res, 400, 'paging not allowed beyond 100');
error(req, res, 400, 'paging not allowed beyond 100');
}
}

search(req.query.q, req.query.type, page, pageSize, req.ip).then((r) => {
const { hits } = r.body;

console.debug(`${req.url} 200: Returning ${hits.hits.length} results for ${req.ip}`);
console.debug(`${req.url} 200: Returning ${hits.hits.length} results`);

hits.page_size = pageSize;
hits.page_count = Math.ceil(hits.total.value / pageSize);
Expand All @@ -64,7 +70,7 @@ app.get('/metadata/:cid/', function (req, res, next) {
let cid = req.params['cid']

if (!cidValidator.Validate(cid)) {
error(res, 400, 'invalid cid');
error(req, res, 400, 'invalid cid');
}

getMetadata(cid).then((r) => {
Expand All @@ -73,16 +79,11 @@ app.get('/metadata/:cid/', function (req, res, next) {
})

app.use(function (err, req, res, next) {
if (process.env.NODE_ENV === 'production') {
// Don't leak details in production
error(res, 500, 'Internal Server Error');
}

if (res.headersSent) {
return next(err);
}

error(res, 500, err);
error(req, res, 500, err);
});

app.listen(port, '127.0.0.1', () => console.log(`ipfs-search search API listening on port ${port}!`));