• Stars
    star
    450
  • Rank 93,869 (Top 2 %)
  • Language ReScript
  • License
    Other
  • Created over 2 years ago
  • Updated over 1 year 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
5,055
star
2

init.lua

Lua
2,727
star
3

vim-be-good

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

.dotfiles

Perl
2,611
star
5

refactoring.nvim

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

kata-machine

TypeScript
1,105
star
7

git-worktree.nvim

Lua
613
star
8

ts-rust-zig-deez

Java
520
star
9

htmx-lsp

its so over
Rust
454
star
10

anime

The repo that everyone deserves
448
star
11

vim-royale

Because Nano sucks
Rust
406
star
12

vim-apm

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

neovimrc

Lua
261
star
14

CHADstack

Dockerfile
252
star
15

fem-algos

FrontEnd Master algorithms!
JavaScript
249
star
16

keyboards

239
star
17

undefined

A project to turn a file of JSON responses into TypeScript types
TypeScript
231
star
18

rust-for-typescript-devs

JavaScript
207
star
19

ansible

Dockerfile
203
star
20

primestack

Rust
135
star
21

ThePrimeagen

109
star
22

vmrss

Shell
83
star
23

web3-smart-contracts

JavaScript
83
star
24

BunSpreader

We spread the buns
Zig
74
star
25

vim-with-me

Rust
73
star
26

fem-algos-2

The Last Algorithm Class You Want
JavaScript
68
star
27

jvim.nvim

A simple json traverser for NeoVim
Lua
67
star
28

aoc

2020
Rust
63
star
29

vimrc

62
star
30

yew-have-ligma

Elixir
61
star
31

htmx_golang

Go
57
star
32

orgwasm

CSS
55
star
33

2-simple-steps

Its literally that simple
TypeScript
54
star
34

fem-htmx-proj

Go
47
star
35

coin-toss-me-daddy

Rust
44
star
36

js-perf-example

TypeScript
40
star
37

vim-nav-playground

C
39
star
38

htmx-class-template

The starter template with server in go or rust
Rust
39
star
39

lsp-debug-tools.nvim

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

neural-js

A kick-ass neural network for javascript
JavaScript
34
star
41

leftPadDeez

nuts
JavaScript
34
star
42

yt

All my yt videos that require to have some codes.
TypeScript
32
star
43

rusty-arduino

Rust
31
star
44

titty-sprinkles

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

htmx-subscribe

HTML
28
star
46

htmx

Rust
27
star
47

public-edging

Rust
26
star
48

jpegdegens

TypeScript
26
star
49

beat-me-daddy

I put my sonic in my pi
Rust
26
star
50

ts-go-rust

JavaScript
26
star
51

go-vs-rust

The greatest cli comparison ever created
Elixir
26
star
52

uhh

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

best-of-stackoverflow

A DRAMATIC READING OF STACK OVERFLOW
23
star
54

objects-to-buffer

TypeScript
23
star
55

bun-vs-node

TypeScript
22
star
56

fem-htmx

JavaScript
22
star
57

rust-wasm-serverless

Rust
21
star
58

json-vs-proto

TypeScript
20
star
59

no-flap-november

the greatest
Go
19
star
60

gspot

Rust
18
star
61

fem-jsperf

JavaScript
18
star
62

ts-go-rust-projector

TypeScript
17
star
63

ocaml-aoc

OCaml
16
star
64

i-fixed

16
star
65

shooter-js

TypeScript
15
star
66

vim-deathmatch

Rust
15
star
67

milo

TypeScript
15
star
68

zig-deez-structures

Zig
14
star
69

big-chungus

is amungus
TypeScript
13
star
70

this-isnt-rust

There is no rust in this suppository
TypeScript
13
star
71

your-first-plugin

Example NeoVim Lua Plugin
Lua
12
star
72

tree-navigation

Lua
12
star
73

more-htmx-eploration

Rust
12
star
74

javascwipt-performance

suck it piq
TypeScript
12
star
75

why-are-promises-slow

they are
11
star
76

real-prog-dvorak-zmk

Rust
11
star
77

tier-list

HTML
11
star
78

projector

Project my config into your prebuild
Go
10
star
79

dev

my next gen build for starting my system
Shell
10
star
80

cargo-chadr

Rust
10
star
81

test-these-besties

Go
10
star
82

chat-js

Rust
9
star
83

he-uses-tabs

Rust
8
star
84

neovim-irc

C
8
star
85

git-bisect

JavaScript
8
star
86

rxjs-examples

JavaScript
7
star
87

jest-mem-test

JavaScript
7
star
88

todo

yes
C++
6
star
89

first-deno-project

JavaScript
6
star
90

fizzbuzz

A real programmers fizzbuzz
JavaScript
6
star
91

ansible-dev-prod

Dockerfile
6
star
92

99-ocaml-problems

6
star
93

neovim-irc-ui

Lua
5
star
94

first-nvim-plugin

The template for writing your first nvim plugin
5
star
95

the-hoff

9000
TypeScript
5
star
96

mini-wasm-env

When full wasms just wont due
C
4
star
97

crypto-legends

Like Apex Legends. Just more, better, faster, and less recoil
Go
4
star
98

keyboard

Simple keyboard
JavaScript
4
star
99

fem-vim

Vim Script
4
star
100

flatbuffers-benchmarks

The hello server that will take in either flatbuffs or json and add one to the `count` field, then resend the data back through the socket connection.
JavaScript
4
star