3

Shall I use mysql events or crone jobs for the mine production in my game? 🤔

Comments
  • 0
    What is the game? Online or what?
  • 0
    @iiii yes. Mmorts online game. Nodejs + Mysql db.
  • 2
    I would disrecommend both.

    Cron is a frickle thing, MySQL events are the epitome of fragility.

    I'd recommend something programmatically that can be adapted to your needs.

    I'm sure that NodeJS has an event scheduling library or sth like that....

    It should be far more suited to your needs.

    MySQL Event scheduling is a pain in the ass to debug and to control, as the database is kind of an autonomous system. Cron is kind of an autonomous system, too. You can wire it up programmatically but there are lots of trip wires (eg. quoting of shell commands, privileges in database / filesystem, logging, ...).

    Libraries will give you an programmatically access that will also allow to be more granular - newer cron job implementations (yes there is not one, but several with different feature sets) like Chrony allow second granularity, MySQL afaik only allows second granularity, too.
  • 1
    @IntrusionCM I have around 12000 entries, the stuff shall run through it once in a while/i don't know yet how often and check every entry and for example if it contains a mine lvl1, it has to update the gold/iron/wood whatever amount of the owner by N amount. I'm afraid to break the node loop with this process. What do you think?
  • 2
    @blindXfish uuuuuurrrrkkssss....

    Fair warning: it's been a long time someone bugged me with NodeJS as I hate JS in it's entirety.

    If I remember correctly, there was an event loop and there were worker threads.

    Worker threads are less efficient for I/O, but great for CPU, as they run outside the event loop I think.

    If you find a library that builds up on worker threads model, which I guess shouldn't be hard, as the event loop seems definitely "wrong" (or better less suited) for this, shouldn't matter?

    (I can be totally wrong here, was last year I think where we had something with NodeJS and processing of scheduled events)
  • 1
    @fruitfcker

    Drop your pants.

    It's spanking time.
  • 0
    Can't you calculate the balance when it is checked based on the last known value and time elapsed? Updating lots of entries periodically doesn't sound right.
  • 0
    BTW since you're talking to a database this is still mainly IO bound, so running it in the main event loop is probably preferable if the main event loop already talks to that database anyway.
  • 0
    @IntrusionCM

    > MySQL Event scheduling is a pain in the ass to debug and to control

    It depends ...

    For regular maintenance jobs I prefer "in
    DB" operations, here events.

    BUT the events just call a procedure wich itself is much more easy to debug.
  • 0
    @k-ko Did they change something?

    I found stored procedures in MySQL a real nightmare...

    Especially debugging, as the only option is afaik to utilize variables and SELECT's to get sth like a debugging log.
  • 0
    @IntrusionCM

    I personally have a helper function which writes log entries to the anyway existing table.

    Most events in my projects "only" handle things like performance collection, optimizations, clearances and such things, no real business logic.
Add Comment