Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


What's the most lightweight server side language for mysql server?
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

What's the most lightweight server side language for mysql server?

Let's say I have hundred of thousands of users submitting pool / vote at the same time

What's the most lightweight server side language to accomplish this?

I am talking about backend, front end is already covered, static page / cache /cdn.

I am looking for saving the users vote.

«13

Comments

  • FAT32FAT32 Administrator, Deal Compiler Extraordinaire

    I would say Node.js or Golang would fit this purpose well.

  • nginx + lua

  • @FAT32 said:
    I would say Node.js or Golang would fit this purpose well.

    Thank you. Probably gonna go with nodejs.

    Thanked by 1FAT32
  • vfusevfuse Member, Host Rep

    Rust

    Thanked by 1ehab
  • With that update rate the db itself will be a bottleneck. You might have to use UDF's (user-defined functions) in mysql, which are written in C. Alternatively, consider something like Redis instead of mysql.

    Thanked by 1bugrakoc
  • Im surprised someone mentioned Rust.

    If no one mentions PHP, there's still hope for humanity.

  • Jona4sJona4s Member
    edited March 2019

    Heres a 20 line Golang code that accepts POST to /vote, and saves to a var.

    https://play.golang.org/p/zq4vW4RRubb

    As said above, don't use MySQL. Try Redis if the db fits in memory, or something like RocksDB if it doesn't.

  • @yokowasis said:
    Let's say I have hundred of thousands of users submitting pool / vote at the same time

    What's the most lightweight server side language to accomplish this?

    I am talking about backend, front end is already covered, static page / cache /cdn.

    I am looking for saving the users vote.

    You are better of using redis or memcached

    The latter can be horizontaly scalled as well

    Node js seems to be a clear choice.

  • @Jona4s said:
    If no one mentions PHP, there's still hope for humanity

    THIS.

  • FAT32FAT32 Administrator, Deal Compiler Extraordinaire

    @Jona4s said:
    As said above, don't use MySQL. Try Redis if the db fits in memory, or something like RocksDB if it doesn't.

    Yes, basically use any non-relational database that is fast. Using key-value pair can ensure the uniqueness of the records too (using username / user ID as key)

  • C

    Jona4s said: Heres a 20 line Golang code that accepts POST to /vote, and saves to a var.

    nope, that not 20 lines :) it's import another library. I can run one liner with completed server ;)

    php -S localhost:9090 /data/server

    .

  • eoleol Member

    Portuguese.

  • bapbap Member

    pool / vote?

    Google Forms.

    Thanked by 1flatland_spider
  • yokowasisyokowasis Member
    edited March 2019

    @bap said:
    pool / vote?

    Google Forms.

    This is a legit answers. I have already considering it. But google forms lack of callbacks.

    Is there a way to use callback when the user succeed submitting the form ?

    I have already succeed integrating google forms to my website. It works as expected, except I don't know how to catch the callback.

  • bapbap Member

    @yokowasis said:

    @bap said:
    pool / vote?

    Google Forms.

    This is a legit answers. I have already considering it. But google forms lack of callbacks.

    Is there a way to use callback when the user succeed submitting the form ?

    I have already succeed integrating google forms to my website. It works as expected, except I don't know how to catch the callback.

    I'm also curious about that, I've never tried it.

    But I've seen someone succeed in doing it. If I'm right you are Indonesian, then try checking the Pakuan university's email registration form.

    :smile:

  • Forth or Lua.

    Thanked by 1uptime
  • @bap said:

    @yokowasis said:

    @bap said:
    pool / vote?

    Google Forms.

    This is a legit answers. I have already considering it. But google forms lack of callbacks.

    Is there a way to use callback when the user succeed submitting the form ?

    I have already succeed integrating google forms to my website. It works as expected, except I don't know how to catch the callback.

    I'm also curious about that, I've never tried it.

    But I've seen someone succeed in doing it. If I'm right you are Indonesian, then try checking the Pakuan university's email registration form.

    :smile:

    I have tried it. People have no idea that I am using Google drive. Basically I am copying the HTML and using Ajax post to submit the form to the Google server. While it works , sometimes problem arise. There is no way to tell whether the form successfully submitted or something wrong. E.g. time out. This results in some users doesn't get their form submitted properly. They just close the browser assuming they have already submitted it.

  • jsgjsg Member, Resident Benchmarker

    In such a situation (100k+ req/s) I wouldn't play with google (or other) web forms at all but do the whole process myself. Reasons:(a) problems (like what you described), (b) hand over is too tricky and too slow.

    I don't see the language as the big problem. Lua (have a look at a lua/terra combo!), nodejs (w/libuv), Go, and some others should do the job. The problem is the DB - but based on what you told us about that (and some things like how you recognize users) - basically nothing - we can't provide good advice beyond (frankly mindless) "useRedis","useXYZ". But I assume that looking up users, checking for multiple votes, and the DB (or table serialization, or ...) will be the trouble spots.

    Thanked by 1bugrakoc
  • williewillie Member
    edited March 2019

    As another matter, if you're taking 1000s of new connections per second and it's an https page, your TLS stack may be a bottleneck. Normally one should prefer using https for everything, but in this case maybe regular http is ok. Alternatively, make sure to set up your stack for a fast cipher suite, ECDH/ECDSA or whatever.

    You might need multiple hosts and a load balancer. 100k requests/sec is really a heck of a lot.

    Also, if you're just counting votes, you don't need a database at all (not even redis) and you are probably better off using in-process memory, perhaps using something like OpenResty if you like nginx and lua.

    If you want a very fast back end for a multicore server, look at seastar.io, but you have to be pretty hardcore to use it.

    Thanked by 1uptime
  • An in-memory data-structure like Redis queue or a lightweight message queue (beanstalkd?) would let you implement pub-sub between multiple front-end servers and a single source of truth (DB) .
    The choice of language is less important than the design of the system.

    Maybe PHP on the web workers(producer) , golang on the backend (consumer) ?

    The correct answer is to hire jsg of course.

  • gnugnu Member
    edited March 2019
    1. Requests hit nginx. Non-blocking is the keyword here. Forget Apache.
    2. Node.js for the backend. Non-blocking and make sure it's setup to utilize all cores (it doesn't by default). Node should saves each entry to Redis (RAM).
    3. Then every X seconds another script (not necessarily Node) reads entries from Redis and inserts them into MySQL (or any classic RDBMS) and deletes those from Redis. But it does so in chunks of 200 (or whatever) entries at once per 1 SQL insert.
    4. Use small data types as much as possible, so integers for everything. Allow text strings only where you have to. Check the length/size of incoming text strings to prevent someone from sending you multi-megabyte text in POST parameters. Malicious 1000 requests x 1MB parameter, oops there goes 1GB+ or RAM.

    Further optimizations (v2)

    1. More CPU cores if you can afford, obviously.
    2. Experiment with something more lightweight than NodeJS. A small Golang binary , etc, but it must be non-blocking and capable of high concurrency.

    Conclusion: The main problem you should concentrate on is that no classic RDBMS (MySQL, Postgres) is going to handle that, so don't save directly to RDBMS.

  • YuraYura Member

    Use Fortran, don't be a nodejs millennial.

  • @Yura said:
    Use Fortran, don't be a nodejs millennial.

    Pre-forktran, even.

  • jsgjsg Member, Resident Benchmarker

    @vimalware said:
    The choice of language is less important than the design of the system.

    True but smartly choosing the language can make async IO and some other things easier (or more cumbersome).

    Maybe PHP on the web workers(producer) , golang on the backend (consumer) ?

    Maybe the voting form can even be a static web page. That would be the easiest and fastest solution. PHP btw. (or Python) won't cut it once one has that kind of amount of req/s.

    The correct answer is to hire jsg of course.

    Thanks so much but that's bad advice. I can do projects like that but I hate them and would touch that kind of project only for a very very good client.

  • NeoonNeoon Community Contributor, Veteran

    If you also go for low memory, I would suggest picking rqlite, which is a sqlite database written in GOLANG which has replica build in.

    It does have a cli and http api, which are easy to use

    Thanked by 1vimalware
  • vimalware said: pub-sub between multiple front-end servers and a single source of truth (DB)

    You're better off without any IPC happening on every single request: that's why you want in-process storage. Since it's for voting, all you have to do is add up the per-process totals once in a while, through Redis or whatever.

    Thanked by 2jsg vimalware
  • BenjiroBenjiro Member
    edited March 2019

    @yokowasis said:
    Let's say I have hundred of thousands of users submitting pool / vote at the same time

    What's the most lightweight server side language to accomplish this?

    I am talking about backend, front end is already covered, static page / cache /cdn.

    Crystal fits ( https://crystal-lang.org/ ). Its like Go for the people that can not stand "if err != nil" :)

    Rust is really overkill for web development and i advice against it unless you have some serious C/C++ background. Both Rust and Crystal use LLVM in the background to compile down AOT.

    Crystal is nice in the sense that people with Ruby experience can get going fairly fast with the language. For people with a PHP or JS background, it may take some time but its not a hard language. A simple webform will probably take you a few hours to write.

    Your looking at processing 30k/s requests per second ( http, https is different issue ) per core with Crystal. So simply set up reuse_port with multiple instances. In regards to speed, Go is by default slower with its default HTTP but if you use fasthttp, then its faster.

    Now the real blocker is going to be your database writes. My advice is to simply have a memory pool and write the results every time your pool hits 1000 requests. Write to database in one move. Single insert, serialized object or json. Do NOT write every form submitting to the database when you get it because it will kill your speed.

    @Jona4s said:
    Im surprised someone mentioned Rust.

    If no one mentions PHP, there's still hope for humanity.

    PHP is good for fast development but to handle 100.000req/x seconds. No ... The way PHP works it can not handle that traffic ( unless you want to balance a few hundred of servers ). Let alone the memory need for every PHP instance lol. Apache is also a bad choice when it comes for this workload.

    Go, Crystal, etc are much better suited for this work because of the way they work. You can get away with PHP IF you run it for instance combined with Swoole. That can handle the load but that it a whole different game.

    The real issue is the writes / database anyway. And potentially HTTPS with this amount of connections.

    Thanked by 1vimalware
  • OpenResty (NGINX + LuaJIT) with MySQL plugin (https://github.com/openresty/lua-resty-mysql).

  • @yokowasis said:

    @FAT32 said:
    I would say Node.js or Golang would fit this purpose well.

    Thank you.

    You know, there's a button for that.
    I think i've told before that i gather all of my thanks at the end of each month and i buy sanitary napkins with them. I just love the sense of extended safety having them provides. Like, nothing can possibly go wrong and cause great emotional distress.

    Thanked by 2eol uptime
  • For write speeds, I would recommend an LSM based DB (like RocksDB) instead of B Tree or B+ trees (like InnoDB, SQLite) due to lower write amplification (fewer disk writes per DB update).

    Maybe something like http://myrocks.io/ (Comparison: https://github.com/facebook/mysql-5.6/wiki/MyRocks-advantages-over-InnoDB).

    Alternately, use SQLite in WAL mode (https://sqlite.org/wal.html)

    Thanked by 1vimalware
This discussion has been closed.