Benchmarking Performance of node.js (cluster) with mysql pools : Lighttpd + PHP?

后端 未结 7 1016
無奈伤痛
無奈伤痛 2020-12-28 12:01

Edit(2): Now using db-mysql with generic-pool module. The error rate has dropped significantly and hovers at 13% but the throughput is still around 100 req/

相关标签:
7条回答
  • 2020-12-28 12:24

    One thing to consider is the driver - performance to databases can be very tied into the specific driver you are using. The most popular mysql driver and the one that is the most actively maintained is https://github.com/felixge/node-mysql. Might get different results with that.

    But if you are stuck at 100 connections, sounds like connections are not being properly closed. I might add a console.log statement in the pools destroy event to make sure it really is executing.

    0 讨论(0)
  • 2020-12-28 12:25

    100 connections is the default setting for MySQL maximum number of connections.

    So somehow your connections aren't being reused for different requests. Probably you already have one query running on each connection.

    Maybe the nodejs MySQL library you are using will not queue queries on the same MySQL connection but try to open an other connection and fail.

    0 讨论(0)
  • 2020-12-28 12:25

    This is a bad benchmark, it should be a simple "hello world", as thousands of benchmarks that prove that nodejs is the "hello world" server fastest of all time :D

    0 讨论(0)
  • 2020-12-28 12:30

    Have you enabled APC with PHP?

    Can you try to enable persistent connections with PHP? e.g.

    $conn = new mysqli('p:localhost', 'root', 'password', 'v3edb2011');
    
    0 讨论(0)
  • 2020-12-28 12:34

    Correct me if I'm wrong, but I feel like you are overlooking something: Node uses a single process to handle every request (and handles them through events, still the same process), while php gets a new process (thread) for every request.

    The problem with this is that the one process from node sticks to one core of the CPU, and PHP gets to scale with all four cores through multi-threading. I would say that with a Quad Core 2.x GHz processor, PHP would definitely have a significant advantage over Node just through being able to utilize the extra resources.

    There is another discussion giving some information about how to scale Node over multiple cores, but that has to be done explicitly through coding. Again, correct me if I'm wrong, but I don't see any such code in the example above.

    I'm pretty new to Node myself, but I hope this helps you improve your test :)

    0 讨论(0)
  • 2020-12-28 12:37

    Aren't you using 10 maximum MySQL connections in Node.js, and 5000 maximum MySQL connections via PHP?

    While you run your tests on either system, I would take a look at MySQL's "SHOW FULL PROCESSLIST".

    0 讨论(0)
提交回复
热议问题