PHP + MySQL is really a combination of rough and tolerance

Source: Internet
Author: User
PHP + MySQL is really a combination of rough and tolerance for a long time, and has been busy with several major projects.

The content of several projects varies greatly, but they all have high precision requirements on payment and settlement. one of them has a large amount of real-time synchronization data.

To what extent? About 30 updated data records are obtained per second on average. the 30 data records trigger the comparison and update of about 200 data records. During the preparation phase for this project around and, I personally felt that PHP + MySQL was difficult to perform this task. net, Java, Scala, golang, and different databases, including pgsql, sqlserver, and mongodb, all made a lot of research and testing preparations. later, Scala was selected. But when it comes to practice, the characteristics of static languages really make me have a lot of inapplicable places, especially servlet containers. every update requires reload ?? In this regard, I may be spoiled by dynamic languages.

In the first stage, I wrote some code for reconstruction and improvement, so I decided to give up the solution of selecting static language to transform the entire project. Because the online system services are too huge and there are a lot of business logic, the PHP version developed earlier has been encapsulated very robust and complete, and the only one that can persuade me to transform it, only performance differences between languages are supported. After some comparisons, especially the comparison between the actual deployment and update of servlet and the existing PHP, I compared a feature list, in addition, each feature actually tests the comparison between the servlet mode and the PHP mode, and finally decides to abandon the scheme of selecting static language to transform the entire project.

In the construction of Web systems, PHP's support for dynamic updates is a very important feature, which may have become the biggest advantage of distinguishing all existing Web development languages. Ruby, node. js, golang, and Java can only dynamically update templates. in the release mode, class library files are loaded in place only when called, never released, compiled into binary files, and pre-loaded.

If we give up the refactoring solution, we need to change our thinking. The original idea was to use the Web as the core of the system. One purpose of the original transformation was to enable the Web to perform some operations and tasks more actively, this allows him to initiate and execute tasks proactively. But in reality, I have already used PHP code in the first stage. I don't want to destroy or refactor it ?? Because at the business logic level, there is no problem. I can fully regard the developed Web as a WebService point. The rest is to deploy multiple Service points and connect external data interfaces with WebService, the WebService initiates management and monitoring of these services.

The following figure shows the general topology:

Each external Service only contains the minimum program logic that implements the operations to be performed, and the core business logic is handed over to WebService. Services do not communicate with each other and do not need to know each other's existence. they must be added, deployed, and updated at will. They are like octopus at your fingertips, but they have their own more specific functions and tasks, but they do not have the ability to think and judge. they are just accurate (especially not accurate) to execute different tasks.

When determining this idea, I did not know its feasibility accurately. The core part of this environment is the capacity of WebService, which is also the most uncertain. However, as time advances, I have no more options. In the external Service section, I chose node. js because of the richness of npm and my own familiarity with js.

Service development is not very difficult, and a task scheduler and WebSocket Server are soon encapsulated. After long-term intensive monitoring, the time delay of the Task Scheduler is within the acceptable range. I previously tested node. when JavaScript is used, he knows that, under the single-core condition and under high-density pressure, he will directly use the computing power available for the CPU to the full load without thinking about it.

Soon, the new Service was deployed and released, and the calibration data and WebService business logic were adjusted. What I have been worried about all the time is that some problems may occur in WebService. why ?? Especially on the test server, it is only one of the cheapest servers (that is, it is useless, as long as the system crashes, I will directly reload from the image), standalone operation, it is not a mess. PHP + MySQL's tolerance capability is beyond my imagination. of course, because of the worries about capacity and computing power in advance and the characteristics of the business logic, I have also designed a multi-layer cache solution, so I have to add Memcache here.

However, the robustness and stability of these services written using node. js are really low, and services are often suspended without any reason. In addition, the memory scheduling and release aspects are not satisfactory. Of course, during Service development, I did not deliberately optimize it (which can be roughly described as rough). after all, many things have not been verified by practice, there is no need to overhead your mind. In my budget, this part will be restructured sooner or later ?? The logic is also complex, and the final solution may not select node. js.

Combined with the earliest research and testing, the reconstruction of the Service now focuses on jvm and golang. After so many years of experience, the jvm has improved its memory management and optimized its experience, there are also a lot of references (let's look at the Google trend, Java is also far ahead in all the development languages in the world), and I have already opened some available code. Golang is definitely a killer language. I believe this language has a better performance than jvm, but I have some concerns when I see its pointer symbol, and its variables are contaminated. this is a little troublesome.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.