• Stars
    star
    462
  • Rank 94,832 (Top 2 %)
  • Language ReScript
  • License
    Other
  • Created almost 3 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Clearly a repo about websockets and their comparison...

Tags

Go vs Typescript: Video 1 of the series is tag go-vs-ts-video-1

How to run perf

node --perf-basic-prof path/to/prog &
# copy the <PID>

Get the repo for generating the flame graphs. This is where the stackcollapse-perf.pl and flamegraph.pl scripts are located.

git clone [email protected]:brendangregg/FlameGraph.git
cd FrameGraph
# Frequency:
#   lower = less probe effect, longer sampling required
#   For this project I used 3000
sudo perf record -F <FREQUENCY>  -ag -p <PID>

# For the `perf` tool, please google how to install.
# sudo perf record -F 3000 -ag -p <PID> # from node
# Must be executed within the same directory as `perf record`.
sudo perf script | ./stackcollapse-perf.pl > out.fold

./flamegraph.pl out.fold > <PICK_A_NAME_FOR_SVG>.svg

Current Project

Video 2 and 3 are going to be likely Go vs Rust vs Typescript, but I want it to be more complex. I want a server that has to perform a ton of operations and have real deadlines.

  • Everything will be done live on Twitch.

Completed

  • We have successfully created the socket pair emitting server in Go, Rust, Typescript, and RxJS + Typescript.

In Flight

  • Working through the TypeScript implementation.

To Be Completed

  • Fill this in me from the future

Test Client

A test client should do the following.

  1. request an Id
  2. connect to the ws server
  3. wait for play command
  4. send fire commands every X amount of milliseconds
  5. Whether client wins or loses, the client should check their stats after each round.

The cycle should repeat starting from point 2 over and over again.

Server

Getting stats

A simple post request for stats with a stat id should return the stats of a given id retrieved from a database.

Server Stats

A post request for server stats should emit the following (these stats are based off the last server stat request)

  • active connections
  • active games
  • stat requests processed
  • stats stored
  • games played
  • shots taken
  • total ticks processed
  • count of ticks exceeding 17ms, 19ms, 21ms, 26ms, 36ms, 50ms, 100ms
    • this will include processing time + sleep time.
    • an Ideally working server will approximately 60 tick server
  • linode stats? Unsure, working with linode on what is available.
Playing the game

The server, when a new web socket connection is established will either start a wait period for the next connection or start a game. The two connections will remain open until one player is defeated. At that point the connection should be closed.

Game Loop

A game loop will be instantiated with two sockets. The game loop will send out a ready and play signal.

Every tick (approx 16 ms) the game loop will execute the following in the following order:

  1. report stats
  2. get a batch of updates to process (msgs from sockets)
  3. process said updates
  4. update every location of items
  5. check for collisions
  6. check for state of game
  7. determine elapsed time and sleep for enough ms to maintain 60fps

this loop will repeat until one player has 0 health

FAQ

What languages

Rust, Go, and Typescript.

  • 69% chance i'll stop trying to make Rust work. Its effing hard.

Idiomatic vs Similar behavior

This is a tough trade off. I want to be able to build the servers in such a way that each one is as "idiomatic" as possible but the following I will concede the attempt.

  1. In places where I don't even know what is idiomatic
  2. Where doing the idiomatic thing would actually be bad for performance
  3. Where doing the idiomatic thing would make the other servers very different in implementation. Thus hard to say its an "apples to apples" comparison.

RxJS?

I do want to make the TS server implemented with and without rxjs. It will likely be pretty hard to do this, but I believe I can :)

Metrics for success?

The primary metric for success will be connections * 1 / (count of bad ticks / total ticks). This should give a relatively interesting score.

Any Secondary Metrics

If I can get linode metrics out via some end point, then I'll also figure out a nice CPU and Memory metric over time.

Expectations?

I expect that Rust will be faster and more memory efficient, but I worry that I am unable to create something that is this. I will likely over clone and over heap use because I am terrible at the language. So this may hinder it.

Second I expect Go to be the easiest to implement, even though of the three languages I am the least experienced in go by a very significant amount.

Lastly, I think implementing typescript with two different methods (rxjs vs not rxjs) will be a pain in the ass and make me want to quit.

More Repositories

1

harpoon

Lua
6,501
star
2

vim-be-good

vim-be-good is a nvim plugin designed to make you better at Vim Movements.
Lua
3,200
star
3

init.lua

Lua
3,166
star
4

.dotfiles

Perl
2,971
star
5

refactoring.nvim

The Refactoring library based off the Refactoring book by Martin Fowler
Lua
2,816
star
6

kata-machine

TypeScript
1,267
star
7

git-worktree.nvim

Lua
689
star
8

ts-rust-zig-deez

Java
605
star
9

htmx-lsp

its so over
Rust
602
star
10

anime

The repo that everyone deserves
546
star
11

vim-royale

Because Nano sucks
Rust
410
star
12

neovimrc

Lua
341
star
13

vim-apm

Vim APM, Actions per minute, is the greatest plugin since vim-slicedbread
Lua
324
star
14

undefined

A project to turn a file of JSON responses into TypeScript types
TypeScript
282
star
15

fem-algos

FrontEnd Master algorithms!
JavaScript
271
star
16

CHADstack

Dockerfile
257
star
17

ansible

Dockerfile
244
star
18

vim-with-me

Go
242
star
19

keyboards

239
star
20

rust-for-typescript-devs

JavaScript
212
star
21

vim-fundamentals

JavaScript
184
star
22

ThePrimeagen

149
star
23

fem-htmx-proj

Go
139
star
24

primestack

Rust
135
star
25

dev

my next gen build for starting my system
Shell
121
star
26

vmrss

Shell
92
star
27

web3-smart-contracts

JavaScript
84
star
28

BunSpreader

We spread the buns
Zig
73
star
29

fem-algos-2

The Last Algorithm Class You Want
JavaScript
70
star
30

htmx_golang

Go
67
star
31

jvim.nvim

A simple json traverser for NeoVim
Lua
67
star
32

aoc

2020
Rust
65
star
33

fem-git

JavaScript
64
star
34

vimrc

64
star
35

yew-have-ligma

Elixir
62
star
36

orgwasm

CSS
61
star
37

2-simple-steps

Its literally that simple
TypeScript
59
star
38

js-perf-example

TypeScript
53
star
39

neural-js

A kick-ass neural network for javascript
JavaScript
47
star
40

vim-nav-playground

C
43
star
41

coin-toss-me-daddy

Rust
42
star
42

htmx-class-template

The starter template with server in go or rust
Rust
40
star
43

lsp-debug-tools.nvim

this probably isn't the droid you are looking for
OCaml
35
star
44

leftPadDeez

nuts
JavaScript
35
star
45

yt

All my yt videos that require to have some codes.
TypeScript
34
star
46

fem-htmx

JavaScript
33
star
47

game-of-life-vwm

Go
33
star
48

rusty-arduino

Rust
31
star
49

titty-sprinkles

Yes... This is the name for my NodeConfEU project
TypeScript
30
star
50

htmx-subscribe

HTML
30
star
51

test-these-besties

Go
30
star
52

htmx

Rust
28
star
53

jpegdegens

TypeScript
26
star
54

public-edging

Rust
26
star
55

beat-me-daddy

I put my sonic in my pi
Rust
26
star
56

ts-go-rust

JavaScript
26
star
57

go-vs-rust

The greatest cli comparison ever created
Elixir
26
star
58

uhh

When you keep forgetting those sweet sweet sweet sweet commands.
Go
25
star
59

best-of-stackoverflow

A DRAMATIC READING OF STACK OVERFLOW
24
star
60

objects-to-buffer

TypeScript
23
star
61

bun-vs-node

TypeScript
22
star
62

tmux-sessionizer

Shell
21
star
63

vim-arcade

21
star
64

fem-jsperf

JavaScript
20
star
65

rust-wasm-serverless

Rust
20
star
66

json-vs-proto

TypeScript
20
star
67

gspot

Rust
18
star
68

no-flap-november

the greatest
Go
18
star
69

ts-go-rust-projector

TypeScript
17
star
70

ocaml-aoc

OCaml
16
star
71

i-fixed

16
star
72

shooter-js

TypeScript
15
star
73

vim-deathmatch

Rust
15
star
74

milo

TypeScript
15
star
75

big-chungus

is amungus
TypeScript
14
star
76

real-prog-dvorak-zmk

Rust
14
star
77

zig-deez-structures

Zig
14
star
78

this-isnt-rust

There is no rust in this suppository
TypeScript
13
star
79

git-bisect

JavaScript
13
star
80

tree-navigation

Lua
12
star
81

more-htmx-eploration

Rust
12
star
82

javascwipt-performance

suck it piq
TypeScript
12
star
83

your-first-plugin

Example NeoVim Lua Plugin
Lua
11
star
84

projector

Project my config into your prebuild
Go
11
star
85

why-are-promises-slow

they are
11
star
86

cargo-chadr

Rust
11
star
87

chat-js

Rust
10
star
88

tier-list

HTML
10
star
89

he-uses-tabs

Rust
8
star
90

neovim-irc

C
8
star
91

jest-mem-test

JavaScript
8
star
92

the-great-sonnet-test

Go
7
star
93

rxjs-examples

JavaScript
7
star
94

ansible-dev-prod

Dockerfile
7
star
95

rfceez

Lua
7
star
96

todo

yes
C++
6
star
97

first-nvim-plugin

The template for writing your first nvim plugin
6
star
98

first-deno-project

JavaScript
6
star
99

fizzbuzz

A real programmers fizzbuzz
JavaScript
6
star
100

99-ocaml-problems

6
star