Home > Java > javaTutorial > body text

The road of Java architect--current limiting technology and various programming languages

巴扎黑
Release: 2017-06-26 11:48:44
Original
1949 people have browsed it

The programming languages ​​currently on the market are mainly object-oriented. Object-oriented must start with some of the most basic things. For example, I got married at the age of 24, otherwise how could I do object-oriented programming. And then you have a baby right after you get married. What if the partner runs away? A new one? If creation and destruction are expensive, it is better to have a child and continue to hold a reference to the object.

Why do some people talk for a long time when they open their mouths, while some people talk only once in a while? According to my observation, two people who work almost equally well will develop better in the future. Let’s feel the reasons from specific examples.

When chatting with friends, really, Renren, which came out a few years ago, always has a bit of a technical geek spirit. When we chat, we talk about technology. People ask me how your videos are stored and played. I said that I only work on content and meta, and the rest has nothing to do with me. Tian'er chatted to death, and his pattern fell into place. If there is a development platform for what I do, it includes uploading videos. First call the cloud storage interface for initialization, and they return us a video media upload URL. The JS side uploads media fragments to the URL. If the network is interrupted or the browser is closed or something, you can call the resume upload interface to continue uploading using the newly returned URL. The resume transfer interface carries the total file size and the size of the files that have been received so far. JS can use this to determine which fragment to continue the transfer from. Cloud storage is in another department. They are responsible for communicating with the cloud transcoding department. Cloud transcoding converts media into various formats. As for converting original high-definition files into various bit rates, how is sampling done, and DRM digital rights management is How to do it is the responsibility of the cloud transcoding department. What strategies do they use internally to distribute it to various DNS nodes? How the scheduling department schedules to save the most precious bandwidth of the video website, I am not very clear about the specific details. The cloud transcoding department passes the converted bit rates and video URLs to us in the form of MQ, and we store them in the database.

Then they asked again, what do you use for MQ? I'm talking about apache's qpidd. Um~~, if people don’t know, the conversation will be boring. So it must be said that MQ is similar, and like rabbit mq, it is based on the AMQP advanced message queue protocol. This is the company's unified cluster, and it is said to be very convenient to install and deploy. Mainstream programming languages ​​also support it, so I use it. Because it is mainly cross-department communication, it is mainly for convenience and saving communication costs, so our message body is json first compressed and then base64. We also don’t use the binary ones of protobuf, because if we encounter a problem, the binary is poorly readable, lacks self-description, and is not easy to troubleshoot.

High-concurrency services must have some emergency plans, such as service interruption, downgrade, isolation, current limiting, asynchronous RPC, etc. For service interruption, downgrade, and isolation, everyone prefers to use Netflix’s open source distributed service elasticity framework Hystrix. Hystrix can also limit traffic. But our service uses guava's RateLimiter, a mature token bucket algorithm, to implement it.

Service current limiting is a very simple matter. Our code only has a few hundred lines, but it contains a relatively complete set of design ideas. The purpose is to implement fine-grained business current limiting based on certain strategies (such as url, platform source, url + platform source).

 

All requests must go through this interceptor. A single current limit holder is defined in this interceptor. This current limit holder is configured according to the configuration. A map composed of the policy and the configured limit for each or each request is returned to the interceptor requesting the corresponding key and RateLimiter. If the interceptor determines that the limit is exceeded, an error will be returned directly without being handed over to the controller for processing. A request type, such as url, a RateLimiter for fine-grained rate limiting.

Of course, in addition to this application-level current limitation, some restrictions on IP session space, request frequency, and concurrency can also be implemented at the nginx level. If you encounter a network attack, try to solve the problem from the operation and maintenance level first, because the higher the level, the impact on services can be minimized.

A good software architecture can meet the quality of the system, enable beneficiaries to achieve consistent goals, support the planning process, guide system development, effectively manage complexity, and lay the foundation for reuse. The foundation can reduce maintenance costs and support conflict analysis.

Most architectures or programming languages ​​come from projects. For example, Stroustrup, the inventor of C++, originally designed this language because he saw that C language caused critical programming problems due to unreasonable initialization parameters. Such bugs are difficult to find. This problem also occurs during cleaning. If you do it and persist, you will indeed succeed. However, everything has a stage of formation and development. Java has been complained about performance issues in older versions, and every version of Java is accompanied by performance improvements, so upgrading the JVM can bring free performance benefits. The final keyword comes to mind when it comes to details. In early versions, the part of the final keyword would be called inline, directly expanding the function without the need for constant pushing and popping of parameters into and out of the stack, which would cause performance overhead. But this will cause a relatively large space overhead when the function body is large. The JVM has been optimized since 1.5, and the final keyword is no longer so important in performance. It turns out that there is a colleague in the company who is very nice and has great ideas. He said: "I always record some of my ideas in a notebook, and then when I look at it after a while, I will find that I only insisted on one of the ideas at the time, did it, and it was successful." I think he is further away from success than he thinks. Because all he had was an idea, but he didn't do it. It seems that there is only the idea of ​​​​JDK1.0, but the distance from success is at least jdk1.5.

Python is famous for its small code size, low maintenance cost, and high programming efficiency. But how many programming languages ​​are not optimized for low maintenance costs and high programming efficiency? So people asked me that search engines are already in flames. Can you really create your own advantages in the future? All I can say is how will you know if you don’t try. "Life is short, I use python". These features of Python can free up more time to pick up girls, but life is short. The advertising words of Python authors give Python vitality. In fact, the simplicity of Python can be seen from its memory recycling. It uses reference counting, so there is no circular reference problem. I did a python project when I was at Renren. There was a time when our leader said that I did the work of eight people by myself. In addition to all the maintenance work on the entire website, I take on all kinds of new jobs. Because of this personality, others really have no way to come to me. I only embarrass myself, not others. At that time, I had been working for less than four years and had been programming for less than two years. I said that I worked as a Japanese translator for the first two years of my work. The reason why we can go to everyone. I just came to Beijing one day, and I was visiting the Summer Palace with my senior. Suddenly I received an interview call from Renren.com. The person on the phone asked me various technical questions, and my answers were all "No." The other end was very nice and said it didn't matter. Finally, there was an interviewer on the other end of the phone, who spoke to me in Japanese and asked me what I had done. She was very satisfied with my answer. She was mainly satisfied because she found that my Japanese was very good. As a result, I became a bridge engineer at Renren.com. I remember that in the article I wrote earlier, in my personal profile, I said that I was criticized by netizens for my language talent. But when I was at Neusoft, everyone said that I had language talent, and I was used to thinking so. I just took it for granted. I am stating something, and I don’t mean to advertise it. I don’t know Python either, and I don’t even know what an open platform is. But I took over the maintenance of the entire open platform by myself because the boss of the open platform left for Meituan. By the way, this boss is really a great guy. He came from Tsinghua University. He started a business, came to Renren, went to Meituan and became P4, and now he is starting his own business. One day, my boyfriend showed me a photo from the Tsinghua Alumni Association and asked me, "Is this person a former colleague of yours?" I said, "Yeah." He said: "The person sitting next to him is our boss." Well, it seems that my male idol has a lot of room for improvement.

I bite the bullet and maintain this open platform. Then the Bubble Fish game will be connected to a Japanese platform. This game is written in python. At that time, this game was very popular. The game company was very busy and had no time to connect it, so they paid us for help. We can only take the code and connect it ourselves. At that time, Renren liked to engage in internal entrepreneurship. We were an overseas business department and we were not making money. I made the connection, and the game party gave us a 100,000 connection fee, and the rest was the game share. I don’t know how much the income was. But this was the only profitable project for us at that time. Python is really easy to learn. I maintain the website during the day, and everyone comes to me. At night, I do the access, study python and access documents, and finish the payment access part in one week. The test environment can be charged. But there was a problem going online. When running the formal environment built by the operation and maintenance MM, something was wrong. Everyone went home in the evening, and I worked on the online environment there by myself. Later, I finally discovered that the version of one part of the installed tool was wrong, but I can’t remember the details. That happened 6 years ago. So I have done python, but I don’t know python.

There is a high wall between Java and C++, which is surrounded by dynamic memory allocation and garbage collection technology. People outside the wall want to enter, but people inside the wall want to get out. You can't be so casual in Java, that is, optimize the memory allocation parameters. Speaking of JVM parameter optimization, in fact, the most commonly used thing that everyone knows and doesn't take seriously is to set the initial maximum and minimum values ​​of the heap to the same value, so as to avoid heap Automatic expansion, adjusting the size of the new generation and the old generation of full gc caused by throughput reduction and delay. It is said that almost all gc operations of the JVM, including minor gc, must stop the world.

Finally, I would like to recommend a foreign website to everyone. Practical tools and tuning techniques are often introduced, focusing on analysis. Representative works include and

The above is the detailed content of The road of Java architect--current limiting technology and various programming languages. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!