Giter Club home page Giter Club logo

bstats-backend's Introduction

Hi, I'm Bastian ๐Ÿ‘‹

Professional full-stack developer & open source enthusiast

Bastian's GitHub stats

๐Ÿ“‹ My Projects

  • Javacord, a popular Java library for creating Discord bots.
  • bStats, the de facto standard for collecting statistics of Minecraft server plugins. Actively used by more than 6,000 plugins on over 200,000 servers worldwide, processing over 3,000,000,000 requests per month.

๐Ÿ“– Publications

bstats-backend's People

Contributors

bastian avatar heipiao233 avatar martijnmuijsers avatar mineyuanlu avatar p3ridot avatar telesphoreo avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bstats-backend's Issues

Improvement to submission overload risk

Regarding PaperMC/Paper#4914

While this was a good change on our end, I have a suggestion for improving it on your end.

The library p-queue is my favorite promise based queue library for NPM, highly used.

Use this library to throttle submission tasks to ensure only X amount can be concurrently processing at a time.

This should be a rather simple and quick change (Sorry don't have time to PR this, but I'm sure you get the gist of what I'm suggesting)

Furthermore, bstats submissions are not end of the world if the request is dropped.

I suggest once the submission has been received over the http endpoints, to not await the promise for completion of the submission, and just quickly tell the submitter "got it" once validation is done, submitting the data into the p-queue to fire when ever its turn comes.

Shutdown of the process does need to block until p-queue's instance .onIdle() method resolves to ensure all pending tasks are flushed before shutdown finishes.

Finally, one final optimization that could be made is if the p-queue size > X, to write the request data to a temporary data file on disk, unload the request object from memory (releasing references to the object), and submit into the p-queue a task that will load the data from FS before proceeding.

You could just do this for all requests to keep it simple, then the p-queue tasks only hold a reference to a temporary file name, and shutdown could let those pending files stay on disk and then only need to flush in-processing tasks at shutdown.

This would guarantee memory stays light even if 10k pending submissions are waiting.

Happy to provide a code review if you need for this (I've done this kind of logic for my own work use plenty)

Data Reliability

I'm creating a multi-server project like this, but for other purposes, and when I was analyzing the http requests from the plug-ins to the backend, I wondered what would tell me if those requests come from a plug-in or from who uses a postman on the internet trying to mess up my data. And after a lot of research, I surrendered to looking at other open source projects, so I looked at yours and realized that you don't do any of that...

i copied the json sent to the server, set it to a single random plugin and changed the data. shutted down the server, opened my postman and sent this json:

https://bStats.org/submitData/bukkit

{
    "serverUUID": "8c5c4bc6-1f94-460f-9c34-677e07629866",
    "playerAmount": 7395,
    "onlineMode": 1,
    "bukkitVersion": "git-Spigot-21fe707-e1ebe52 (MC: 1.8.8)",
    "bukkitName": "CraftBukkit",
    "javaVersion": "1.8.0_271",
    "osName": "Windows 10",
    "osArch": "amd64",
    "osVersion": "10.0",
    "coreCount": 6,
    "plugins": [
        {
            // EssCore is the random plugin
            "pluginName": "EssCore",
            "id": 2729,
            "pluginVersion": "1.1.0",
            "customCharts": []
        }
    ]
}

And as you can see here (https://prnt.sc/xddqlx) it worked.

I remembered several times that friends asked me if a developer was good and some showed me their bstats graphics with a supposed incongruity of the data looking like the print. I'm not saying that anyone has done this before, but it would be a good way to pass development reliability.

I don't understand authentication models very well or even if it is possible to detect a server or not, but I would try to find a way, as it would be very bad for a project of this level to have untrusted data.

Disable CORS

At the moment, CORS is enabled.:

const app = await NestFactory.create(AppModule, { cors: true });

Currently, this is no problem as the backend only serves data that is publically available. But as soon as we introduce protected routes, it should be disabled.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.