Personal Summary after completing the advertising system

Source: Internet
Author: User

From 7.11 to August, the advertising system was basically complete. Many problems have been encountered in this process, and many details have not been well handled. Therefore, make a conclusion and make a memo to avoid quickly and correctly solving the same or similar problems in the future.
1. absorb knowledge and new things
(1) database usage
Open-source Library: one is Google's ctemplate and the other is haxx's curl library.
HTTP Library: HTTP Request Parsing and HTTP organization response
Other libraries

Database usage:
First, you need to read the help documentation to quickly find out how to use the library. Second, you need to read the help documentation for some details about the functions used. If there is no documentation, you need to read the source code. You cannot use the function name to guess its function. for the use of the company's previous libraries, the key functions should be checked for implementation to avoid errors during use and processing. Finally, we need to perform a unit test to test whether the processing logic is met in various situations.

Note during compilation: All static libraries are used.
In Windows, curl defines the macro http_only during compilation, and when the curl static library is used, sets the macro curl_staticlib.
Ws_32.lib should be appended to the connection class library, and libc. Lib should be ignored based on the situation
In Linux, when curl is./configure, you must specify -- disable-LDAP -- disable-LDAPS. Other parameters are determined based on help. When using the curl library, you must specify-lidn-LRT before
When using ctemplate in Windows, you must specify the compiling condition/d ctemplate_dll_decl =

An error message may occur when atomic operations may be compiled in Linux. You need to specify the compilation conditions according to the system conditions.
For example,-March = i686

(2) about HTTP
As early as watching nginx, I have already read the HTTP protocol and the format of the HTTP request and response time. However, when using nginx, it is simply based on the existing http-related class library, without careful consideration, the desired response information is not set during the response. It means that a lot of things will not only work after reading them, but you must think more about it in actual use. consider why it works, whether it meets the Protocol requirements, and whether it can be parsed by browsers and servers.

(3) Multithreading
For data synchronization between threads, consider whether the lock can be recursive.
The thread must be started multiple times to avoid unexpected errors.

(4) Io Model
Asynchronous blocking IO: Io multiplexing (non-blocking Io + select/epoll)
Asynchronous non-blocking IO: Unknown for Linux AIO/Windows
(5) Two multiplexing models: reactor and proactor
Multiplexing: reactor, proactor
Reactor: Io multiplexing
1. register the read-ready event and corresponding event processor;
2. Event separator wait event; (select/epoll)
3. When the event arrives, the separator is activated and the processor corresponding to the separator call event is activated (read/write events are handled separately)
4. The event processor completes the actual read operations, processes the read data, registers a new event, and then returns control.

Proactor: use Asynchronous io (such as AIO) to focus only on completed events
1. The processor initiates an asynchronous operation and pays attention to the I/O completion event. (The buffer address, size, and other information will be filled when an asynchronous operation is initiated)
2. The event splitter waits for the Operation to complete the event;
3. When the splitter is waiting, the kernel executes the actual I/O operations in parallel, stores the result data into the User-Defined buffer, and finally notifies the event splitter to complete the read operation;
4. Call the processor through the event splitter after I/O is completed;
5. The event processor processes data in the User-Defined buffer;

2. STL
The selection of containers is incorrect. When vector is used to it, it is used to vector. When many containers are deleted, the efficiency of vector is not high. Efficiency must be considered.
Regarding the container deletion, the iterator will be invalid. It is safe to delete the container in two ways. 1. Use erase to return the location of the next iterator after deletion, 2. Add an iterator to save the next position before deletion.
Using container. Erase (ITER ++) may be invalid and has been encountered in deque.
Second, if a large structure or class is stored in the container, the pointer is saved, and a simple data type is saved on the key.
STL exception

3. About class design
There is a lack of overall design in the entire class, so you need to increase this knowledge.
Internal interfaces: simplify operations as much as possible. In particular, the logic of the main functions must be clear, and relevant functions can be decomposed and refined, so that the interface is clear and easy to read and maintain. Next, we need to clearly describe the meaning of the returned values.
Data Types: Consider the internal data types and locks and the byte Sorting Problem in each structure. (It may also be related to experience)

4. pointer and memory
Before using the memory, you must think about the various possibilities for allocation and release. You can use the memory pool for management, or you can use the cmd_ptr for reference counting Management (this has never been used)
Memory pool size control. You can adjust the size of the memory pool according to the actual environment to avoid endless memory allocation.
After the memory is recycled, the pointer becomes invalid and the associated pointer memory is recycled in a unified manner:
Note that many bugs may be caused by these problems during subsequent tests. Before use, draw a sketch of various relationships to describe various situations, so that you can easily know where to delete or recycle them.
Memory, so whether there are related pointers pointing to other memory blocks, whether these memory blocks are also necessary.
Memory Test problems:
I tried several tools in windows and it didn't feel very effective.
Valgrind is a powerful tool used in Linux. It can better know the reason why the program exits, which access is invalid during the running process, and which memory usage is leaked, which are possible leaks?
If-G is added when gcc/g ++ is generated, it will show which function and row of CPP are faulty.

C ++ Memory Management

5. Test and debugging
Test vc9/VC10 DLL on Windows. 1. Start the DLL and load it to the append process for breakpoint debugging.
2. Open CPP before starting the DLL. In the project that starts the DLL, set the breakpoint for debugging.
On Linux, you can view the process number after starting the program, and attach GDB-attach to the process for debugging. GDB debugging is not convenient for IDE debugging, and may be less useful for GDB.

6. Details
When considering the overall internal processing process, I did not think too carefully after the first consideration. After the preliminary process is completed, it is found that there are still many details to be modified, which may allow
However, some details are not well considered, which wastes time, for example, whether the URL parameter value is a string or an int value,
Or use usleep in Linux as a magnitude of the difference between sleep and sleep, because the debugging lasted two days.
Therefore, in general, writing code is faster, but how can we avoid having to spend more time adjusting and correcting these minor errors after writing them, or testing them before they can be modified based on the feedback,
These results in low productivity.

PS: Object declaration reference, referencing classes in other locations.

7. About the learning plan
C ++ memory management,

UNP,
Boost library,

Network Programming,
In terms of design patterns,

Pthreads programming,
Windows core programming/network programming,

Makefile deep learning,
Use VI for development, rather than simple and practical

Introduction to algorithms,
TCP protocol volume 1

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.