Skip to content

Instantly share code, notes, and snippets.

View kprotty's full-sized avatar

protty kprotty

View GitHub Profile
@kprotty
kprotty / HttpResults.md
Last active April 6, 2019 21:08
Benchmarks of different http server libraries and tcp server implementations

wrk -t8 -c128 -d10 --latency http://localhost:12345

Golang

Running 10s test @ http://localhost:12345
  8 threads and 128 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   380.53us    1.08ms  36.06ms   94.87%
const std = @import("std");
const builtin = @import("builtin");
pub fn main() !void {
if (std.os.argv.len < 2)
return error.NeedsIterationArgument;
const FIB = 35;
const RESOLUTION = Timer.Resolution.Millisecond;
const ITERATIONS = try std.fmt.parseInt(usize, std.mem.toSlice(u8, std.os.argv[1]), 10);

Gigantic MICE Protocol

A small interpretation of part of the Gigantic MICE protocol realized by Gabs. This is mostly just what I understand from it and may not accurately depict what its really doing. For most references, i'd say check out gab's ruby version as well as the decompiled protocol code in IDA or similar

Connecting

Theres two servers used to implement gigantic's party system: The Data server and the Mice server. Using a patched ArkSDK (you can find more info on that in the repo) it will attempt to connect to the Data server by requesting POST http://dataserver/auth/0.0/arch/auth with an arc_token and version encoded through application/x-www-form-urlencoded. An example of what should be returned can be found Here. This returned json contains:

  • the user token
  • address of the Mice server to connect to
  • the SALSA_CLIENT_KEY and SALSA_SERVER_KEY (which should match that of the server)

Authe

UPDATE:

These results are invalid. Some of the server implementations don't parse correctly and rust-tokio/ponylang-tcp don't seem to parse at all. See here for better benchmarks: https://gist.github.com/kprotty/5a41e9612657de00788478a7dde43d78

====

wrk -t4 -c128 -d10 --latency http://localhost:12345

  • Machine:
    • Intel Core i7-6700k (4 cores, 8 threads, 4.2ghz)
    • 16GB DDR4 2400mhz RAM
    • Arch Linux, Kernel 5.2.8
const IoStream = struct {
pub const Readable = u2(0b01);
pub const Writeable = u2(0b10);
pub const Disposable = u2(0b00);
reader: Event,
writer: Event,
pub fn init(self: *@This()) void {
self.reader.init();
@kprotty
kprotty / HttpServer.c
Last active September 27, 2019 03:43
#include <sched.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdatomic.h>
#include <sys/syscall.h>
#include <linux/futex.h>
/////////////////////////////////////////////////////////////////////
// Global Queue Mutex Lock/Unlock
@kprotty
kprotty / Results.md
Last active November 14, 2019 03:47
Mutex benchmark

zig build-exe --release-fast rbench.zig && hyperfine ./rbench --warmup 8

  • Intel Core i5 8265U - Linux 5.3.10
  Time (mean ± σ):     430.7 ms ±   5.9 ms    [User: 3.041 s, System: 0.197 s]
  Range (minmax):   422.2 ms439.4 ms    10 runs
  • Intel Core i7 6700k - Linux 5.3.10
  Time (mean ± σ):     232.4 ms ±   2.0 ms    [User: 1.678 s, System: 0.134 s]
  Range (minmax):   227.9 ms234.9 ms    12 runs
const std = @import("std");
const builtin = @import("builtin");
const assert = std.debug.assert;
const testing = std.testing;
const SpinLock = std.SpinLock;
const c = std.c;
const linux = std.os.linux;
const windows = std.os.windows;
pub const Event = switch (builtin.os) {
const std = @import("std");
const builtin = @import("builtin");
pub fn main() !void {
const thread = try std.Thread.spawn(@as(usize, 0), entry);
thread.wait();
}
pub fn fmain() void {
const arg = @intToPtr(*c_void, 1337);
const Task = struct {
next: ?*Task,
};
const GlobalQueue = struct {
lock: std.Mutex,
head: ?*Task,
tail: ?*Task,
size: usize,