Skip to content
Merged
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
10 changes: 5 additions & 5 deletions frameworks/JavaScript/spliffy/benchmark_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"database_os": "Linux",
"display_name": "spliffy",
"notes": "directory based routing for node",
"tags": ["broken"],
"tags": [],
"versus": "nodejs"
},
"mongodb": {
Expand All @@ -42,7 +42,7 @@
"database_os": "Linux",
"display_name": "spliffy",
"notes": "directory based routing for node",
"tags": ["broken"],
"tags": [],
"versus": "nodejs"
},
"mysql": {
Expand All @@ -65,7 +65,7 @@
"database_os": "Linux",
"display_name": "spliffy",
"notes": "directory based routing for node",
"tags": ["broken"],
"tags": [],
"versus": "nodejs"
},
"postgres": {
Expand All @@ -88,9 +88,9 @@
"database_os": "Linux",
"display_name": "spliffy",
"notes": "directory based routing for node",
"tags": ["broken"],
"tags": [],
"versus": "nodejs"
}
}
]
}
}
4 changes: 2 additions & 2 deletions frameworks/JavaScript/spliffy/db/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {

bulkUpdateWorld: async worlds => Promise.all(
worlds.map( world =>
execute( 'UPDATE world SET randomnumber = ? WHERE id = ?',
[world.randomnumber, world.id] ) )
execute( 'UPDATE world SET randomNumber = ? WHERE id = ?',
[world.randomNumber, world.id] ) )
).then( () => worlds )
}
57 changes: 21 additions & 36 deletions frameworks/JavaScript/spliffy/db/postgres.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,29 @@
const { Client, Pool } = require( 'pg' ).native;
const cpus = require( 'os' ).cpus().length
const postgres = require('postgres');

let clientOpts = {
host: process.env.DB_HOST || 'localhost',
user: 'benchmarkdbuser',
password: 'benchmarkdbpass',
database: 'hello_world'
};

let pool

const query = async ( text, values ) => ( await pool.query( text, values || undefined ) ).rows;
let sql;

module.exports = {
async init() {
const client = new Client( clientOpts )
await client.connect()
const res = await client.query( 'SHOW max_connections' )
let maxConnections = Math.floor( res.rows[0].max_connections * 0.9 / cpus )
//1 worker per cpu, each worker pool gets a fraction of the max connections
//only use 90% to avoid too many clients errors
pool = new Pool( Object.assign( { ...clientOpts }, { max: maxConnections } ) )
pool.on( 'error', ( err ) => {
console.error( 'Unexpected client error', err )
} )
await client.end()
sql = postgres({
host: process.env.DB_HOST || 'tfb-database',
user: 'benchmarkdbuser',
password: 'benchmarkdbpass',
database: 'hello_world',
fetch_types: false,
max: 1
});
},
allFortunes: async () =>
query( 'SELECT * FROM fortune' ),
allFortunes: async () => await sql`SELECT id, message FROM fortune`,

worldById: async ( id ) =>
query( 'SELECT * FROM world WHERE id = $1', [id] )
.then( arr => arr[0] ),
worldById: async (id) => await sql`SELECT id, randomNumber FROM world WHERE id = ${id}`.then((arr) => arr[0]),

allWorlds: async () =>
query( 'SELECT * FROM world' ),
allWorlds: async () => await sql`SELECT id, randomNumber FROM world`,

bulkUpdateWorld: async worlds => Promise.all(
worlds.map( world =>
query( 'UPDATE world SET randomnumber = $1 WHERE id = $2',
[world.randomnumber, world.id] ) )
).then( () => worlds )
}
bulkUpdateWorld: async (worlds) => {
const sortedWorlds = [...worlds].sort((a, b) => a.id - b.id);
await sql`UPDATE world SET randomNumber = (update_data.randomNumber)::int
FROM (VALUES ${sql(sortedWorlds.map(w => [w.id, w.randomNumber]))}) AS update_data (id, randomNumber)
WHERE world.id = (update_data.id)::int`;
return worlds;
}
}
46 changes: 26 additions & 20 deletions frameworks/JavaScript/spliffy/fn.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
module.exports = {
parseCount: ( i ) => Math.min( Math.max( parseInt( i, 10 ) || 1, 1 ), 500 ),
randomId: () => Math.floor( Math.random() * 10000 ) + 1,
randomUniqueIds: ( count ) => {
const used = new Map()
const ids = []
for( let i = 0; i < count; i++ ) {
let id = module.exports.randomId()
if( used.has(id) ) {
for( let j = 0; j < 10000 - 1; j++ ) {
if( !used.has(id) ) break
id++
if( id > 10000 ) {
id = 1
}
const parseCount = ( i ) => Math.min( Math.max( parseInt( i, 10 ) || 1, 1 ), 500 );

const randomId = function() { return Math.floor( Math.random() * 10000 ) + 1; };

const randomUniqueIds = ( count ) => {
const used = new Map();
const ids = [];
for( let i = 0; i < count; i++ ) {
let id = randomId(); // Use the locally defined randomId
if( used.has(id) ) {
for( let j = 0; j < 10000 - 1; j++ ) {
if( !used.has(id) ) break;
id++;
if( id > 10000 ) {
id = 1;
}
}
used.set(id, true)
ids.push(id)
}
return ids
},
}
used.set(id, true);
ids.push(id);
}
return ids;
};

module.exports = {
parseCount,
randomId,
randomUniqueIds
};
Loading
Loading