What is the difference between programming when the amount of data is large and when it is small?

When I first joined Sohu in 2009, I only had more than half a year of work experience, and I didn't know what high concurrency was and what big data was.
Entering the Product Technology Center, taking over the video module, it is the simplest function.

When a user clicks on a video, the number of video clicks is +1.
Memcache is used for caching.

This TMD is already simple and can no longer be operated easily, but after the modification and release, they found that the number of videos on demand would go backwards.
It was originally 18834 times of on-demand, but clicked once to play, instead of 18835, it became 18830. My

heart is broken. Can't see where the code is wrong at all.
Later, various debugging, looking at the log, and slowly see the doorway.

For the first time, I feel what is called concurrency. At that time, there seemed to be more than 100 or more than 200 concurrency per second? I don't remember much, but some popular videos were played more often, and they supported playback on QQ space at that time.

It can be seen that the number of on-demand records recorded in the log is completely chaotic.
Totally messed up!

After thinking about it for a long time, I realized that NND, it takes time to fetch data from Memcache. I don't remember how many MS this time is.
I hate drawing the most:
in short, when a single user accesses it like this


1. User A clicks a video ==" to get data from Memcache, such as 10086
2. User A does +1 operation = "10087
3. User A saves it into Memcache =>10087


Don't ask me why I use Memcache instead of DB directly.

It's a very, very simple logic.



This is the case when multiple users access.

1. User A clicks a video = "fetches data from Memcache, such as 10086
2. User A does +1 operation =" 10087
3. User B clicks a video = "fetches data from Memcache, still 10086
4. User C Click the video once = "fetch data from Memcache, still 10086
5. User D clicks video once =" get data from Memcache, still 10086
6. User E clicks video once = "fetch data from Memcache, still 10086
7. User F clicks a video once = "fetches data from Memcache, still 10086
8. User G clicks a video once =" fetches data from Memcache, still 10086
9. User H clicks a video once = "fetches data from Memcache , still 10086
10. User A saves into Memcache=”10087
11. User B does +1 operation=”10087
12. User C does +1 operation=”10087
13. User B saves it into Memcache=”10087
14. User I clicked a video = "fetch data from memcache, the data is 10087
15. User I does +1 operation =" 10088
16. User I saves it in Memcache = "10088
17. User C saves it in Memcacche = 10087


Do you understand?
Frankly speaking, I was confused and didn't know what to do. Later, President Shen taught me how to use the lock.
Um. Speaking of which, it would be nice if Memcache had atomic +1 operations directly.

Also used concurrentHashMap and so on.



Ma Dan, can't pass the picture. So be it.
It's useless to ask, the slag network can't upload pictures.


To put it simply, when the data is taken out and written back in, other users happen to also obtain the data and write it in.
The error lies in the network transmission of these MSs.


This is what is meant by so-called concurrency. Logic that does not fail in a single thread becomes a definite vulnerability in the case of concurrency.
This is also the reason for adding various locks to Mao.



In addition, it didn't take long before I needed to build an index on the database, and the DB was not large, that is, tens of millions of pieces of data.
Ma Dan, I was young and ignorant, and I didn't even know it was an online database.

After connecting with Navicat, I directly clicked to build the index.

So. I won't talk about the rest, the company exploded in an instant, and the page below the video couldn't be opened.

I was still stunned. Later, I realized that the time for indexing tens of millions of TMD data and indexing dozens of data is not of the same order of magnitude.

I have never considered the scheme of building an index without locking the table.

Later, Brother Peng came over and asked me how to build an index online in broad daylight. I said innocently that I didn't know it was an online database.
I still silently added a sentence in my heart. I don't know how long it will take to build an index.


One is a very simple video playback count + 1, and the other is a very simple DB indexing.
Small amount of data, you can play as you like without concurrency.


These two things happened about a month or two after I joined the company, and I am very grateful to Sohu for their tolerance. As one of the three major portals at that time, Sohu’s colleagues at the time were very, very good, and I learned a lot from them. .

However, at that time Sohu had no QA, no operation and maintenance, and it was all done by engineers consciously.
Later, when I was a white society, it was even more speed and efficiency like a god.

After I left Sohu, I couldn't find a colleague with professionalism, good skills and responsibility like my current colleague.
There is no way but to go through various processes to ensure that online failures do not occur.

So I keep thinking, how many programmers are lucky enough to have access to these top engineers? Can you access big data and high concurrency business scenarios?

I've seen people with 3 to 5 years of work experience who don't know how to type logs. If there is an online fault, it's purely guesswork without reading the logs.
The reason why the Internet can promote the rapid development of technology, application scenarios are very, very important factors.


That's the difference between doing exercises on your own and actually doing projects, right?
When the code requirements are strict, the project name, function name, package path, which ones to write unit tests and which ones not to write should be unified.
Why do you pay attention to this when you write it yourself?



==========Add another paragraph ===================
The Sohu Product Technology Center in 1.08 does not have QA or O&M. . A year after the White Society project started, there seems to be no QA or O&M, I can't remember. White Society is a product technical team collaboration project with more than 60 people. Now I admire Mark who can lead so many engineers to launch the internal test within 3 months and officially launch within 6 months. Without QA to verify, I can only say that the Sohu engineers at that time were very strong, strong, strong, strong. In the team I took after, there was no QA. . .

2. When I entered, I was not an intern, but a regular employee.
3. When I entered, I only had 7 months of work experience. I will list what I would have at that time before I entered Sohu.
4. There were many great people in Sohu at that time, Yuan Tao, Zhongbing, Xiaogang, Hu Wei, Jizi, Sister Lin, and Mr. Shen the most admired were all the best engineers I have ever seen. There is no such thing as Problem now. It is a pity that they are scattered in various companies as senior architects and CTOs, and they often work in Baidu, Sina, Ali, Didi, Tencent, JD.com and other companies.
5. At that time, memcache was used a lot, and MQ was only used in the white society later, and it also stepped on a lot of pits.


Briefly talk about my technical level at that time, and give you a reference.

During the master's degree, I basically didn't write much code, and I wrote all the papers. In addition, the undergraduate course was computer network and self-examination, which was basically not related to writing code.

Therefore, basically all coding experience comes from after graduation. At that time, I only worked on two projects, one was an internal CRM system, which took about 3 months, and I learned a little bit, Spring, Mysql, JDBC, hibernate, jsp, js, html, eclipse, tomcat.
After doing a short-color Wap project, I learned Maven, WebService, shell, and memcache.

That project is a telecommunications project. Each province has an independent version, and each province has its own interface. It is very troublesome to change things every time.
When I was doing it, I felt that it was wrong. When I read a book before, I saw a little design pattern, so I tried to communicate with the supervisor.

Can we use a unified set of Models internally, and map all the non-uniform names of external provinces to our own internal unified Model.

In this way, if you change it again, it will only change the external interface part. This part of the code can be changed no matter how many changes or accesses are made in the future.

Our own internal processing flow has basically remained unchanged, so we don’t need to create more than 30 branches on a project, and we don’t know which branch to fix every time we fix a bug.

But the supervisor at the time completely ignored me, and because of this incident, he resigned in anger, not knowing how Sohu found me.
Anyway, it was also a sea vote and a blind vote at that time.

I remember very clearly during the interview that Sister Lin and Mark met with me separately and asked me how much I expected to be paid. I said my current salary is 5K and the expectation is 6K. Sister Lin and Mark didn't say anything. Just after the interview, HR called me and told me that I will give you 6.5K, and there is also a performance award, which is much higher than your expectations.

At that time, I immediately realized how stupid I was. Ma Dan must have asked for a salary that was too low, and it would be too embarrassing to say it.
Sister Lin said that there were many people with more experience and higher level than me at that time, but Sister Lin said that when I talk about things, I am coherent and clear, so I came in.

Um. I still remember Sister Lin said that basically Sohu's engineers grew up in about a year, and she also hoped that I could stand alone within a year, but after a year I left for various reasons.
Now think about it, which leader of the first-tier company is willing to spend a year to cultivate a new person? It was just that I was so ignorant at the time that I couldn't understand it at all. It was not until later that I spent a lot of thought on leading the team, and seeing the people I brought up leaving one by one and growing up one by one, did I slowly realize a little bit of what it meant to let a new person go to Sohu at that time.

At that time, there were 6 people in a group, and I was the best, um.
Therefore, the industry has been saying that Sohu is the Huangpu Military Academy in the IT industry. I agree with this 100%.

Just, unfortunately, um.
Sohu's White Society is also the most efficient product I have ever seen, with the highest code quality, almost no bugs, the most new technologies introduced, and the best product experience.

It has been abandoned now, and basically all functions can’t be used after I get on it. I still log on occasionally, and occasionally I will tell my friends, if you see it, this is what I did, this is what I did, this is still I made it.

==========Add another paragraph =============

Later, when I built my own team, I basically paid attention to bringing new people.
I have always felt that the level is high or low, the foundation is strong or weak, and the attitude must be good.

If you are a newcomer, and you don't have the desire to work hard and become a technical expert, how can others help you do these things?
Many times, it's not that others force you to do things, but you feel their professional attitude.

Most companies are architects to talk about how to do this project. However, the strategy of Sohu Product Technology Center is that all the project designs are initiated by engineers. Who is responsible for this module, who is responsible for all the design of this module, from DB to cache to From the architecture to the details of the technical solution, the leaders are only responsible for the review.

So the atmosphere at the time was that the tech giants around me were particularly high-minded and said that I would use this solution and that technology to solve this problem. Look at Facebook, they used this, Myspace used this, and Twitter used this, for Mao’s sake. The ____ does not work?

Otherwise, this open source framework is not good and has defects. We have to make our own set. It is very simple, very easy, and there is no risk. You can see that I have made a demo.

In fact, some details have been written in the previous post. After all, it has been too long, and I may remember it wrong myself.
When I answered this time, I also scolded a group of {XX} from Zhihu just a few days ago. I wrote more to calm down, and by the way, I also reminded those new programmers.

Projects are very important, and it is no exaggeration to say that a project achieves a group of people.
Whether it is WeChat, Weibo, Didi, or JD.com, they all grew up by solving application scenarios.

However, it is difficult for most applications to have big data or high concurrency scenarios. In fact, the solutions are similar, but you can really feel it.

For example, when the Footprint server was paralyzed before, Jinshan Cloud's Zhu Hua led the team to support it. In my impression, the overall structure was optimized and adjusted in two or three weeks.

Whether these things are difficult to say or not depends on whether you can actually get in touch with them.

It's like, that's the value I'd like to be able to contribute to this question.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326402923&siteId=291194637