Skip to content

Instantly share code, notes, and snippets.

View sidorares's full-sized avatar

Andrey Sidorov sidorares

View GitHub Profile
@sidorares
sidorares / README.md
Last active January 31, 2024 20:18
node.js conventions and best practices

Node.JS best practices and conventions

This is not about JS style

Advice: if you have style guide / policy, apply it automatically ( in the editor or git hook ) https://github.com/jshint/fixmyjs

Collection of (mostly) JS styles (pick one you like or write another one if none fits you)

// repro for https://github.com/sidorares/node-mysql2/issues/2090
// the code prints "done" bit after cpu spikes to 100% and the process never finishes
class TextRow {
constructor(fields) {}
next(packet, fields, options) {
this.packet = packet;
const result = {};
// "t_id_0": LONGLONG
result["t_id_0"] = packet.parseLengthCodedInt(false);
// "t_id_1": LONGLONG
@sidorares
sidorares / nodeconf_2011.md
Created May 7, 2011 01:16 — forked from guybrush/nodeconf_2011.md
a list of slides from nodeconf 2011
@sidorares
sidorares / benchmark.md
Last active March 29, 2022 12:30
node-mysql2 benchmarks

Benchmarks of node-mysql vs node-mysql2 drivers

Test1:

for each http request, query first 3 rows of mysql.user table and render results using jade template.

Notes: This tests column definition parser (user table has 43 columns), row parser (3x43 values) and access time to result. Also this is test of how well event loop, GC, http parser and mysql driver work together. To compare mysql overhead with http + jade rendering + data transfer, there is another endpoint that renders exactly the same rows of data from memory without fetching them from mysql server.

@sidorares
sidorares / createpixmap.c
Created May 3, 2012 04:09
create 32 bit pixmap test
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
int ApplicationErrorHandler(Display *display, XErrorEvent *theEvent)
{
(void) fprintf(stderr,
"Ignoring Xlib error: error code %d request code %d\n",
theEvent->error_code,
const { performance } = require("perf_hooks");
const minus = "-".charCodeAt(0);
const plus = "+".charCodeAt(0);
const dot = ".".charCodeAt(0);
const exponent = "e".charCodeAt(0);
const exponentCapital = "E".charCodeAt(0);
function bufToFloat(buf, start, len) {
let offset = start;
;(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var BigNumber = require('bignumber.js');
/*
json_parse.js
2012-06-20
Public Domain.
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
// scraped from https://mariadb.com/kb/en/mariadb/documentation/sql-language-structure/mariadb-error-codes/
//
module.exports = [
[
"1000",
"HY000",
"ER_HASHCHK",
"hashchk"
],
[
const mysql = require('mysql2');
const server = mysql.createServer();
server.listen(3307);
let connectionId = 0;
server.on('connection', conn => {
connectionId++;
console.log(`New connection ${connectionId}`);
let acceptSalt = null;
node-mysql2:
wrk git:master ❯ ./wrk -c 200 "http://localhost:8080/mysql?queries=1" -d60
Running 1m test @ Chttp://localhost:8080/mysql?queries=1
2 threads and 200 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 43.77ms 20.00ms 116.91ms 65.06%
Req/Sec 3.00k 1.00k 4.00k 49.94%
397508 requests in 1.00m, 69.67MB read
Requests/sec: 6624.97