FC middleware message queue and a Btree + B + tree + FastDFS distinction security design patterns + + serialization and deserialization + + Python memory management transaction Redis

1. Message Queuing related topics

1.1 Advantages of using message queue (or message queue Why?)

  • (1) Decoupling
    : traditional model
    Here Insert Picture Description
    disadvantages of the conventional mode: inter-system coupling is too strong, as shown above, system A and system B directly invoke code in the code system C, D if the future access system, system A further We need to modify the code too much trouble!

Middleware mode:
Here Insert Picture Description
the advantages of intermediate modes: writes messages to the message queue, the system requires its own subscription message from the message queue, so that the system A without any modification.

  • (2) Asynchronous
    traditional model:
    Here Insert Picture Description
    shortcomings of traditional models: some non-essential business logic runs in a synchronized manner, too time-consuming.

Middleware mode:
Here Insert Picture Description
the advantages of intermediate modes: writes messages to the message queue, the non-essential business logic operates in an asynchronous manner, to speed up response

  • (3) clipping

Traditional model
Here Insert Picture Description
disadvantage of conventional modes: large concurrent time, all requests to the database directly dislike, resulting in connection failure database

Middleware mode:
Here Insert Picture Description
the advantages of intermediate modes: A system in accordance with the amount of slowly concurrent database can handle, and slowly pull message from the message queue. In production, this short peak of the backlog is allowed.

The disadvantages of using message queues 1.2

  • Reduce system availability : Do you think, ah, other systems would have just run properly, then your system is normal. Now you have to give a message queue in, that message queue hung up, your system is not the Oh. Thus, reducing system availability
  • System complexity increases : it wants to consider many issues, such as consistency, how to ensure that messages are not repeated consumption, how to ensure the message to ensure reliable transmission. Therefore, something needs to be considered more and system complexity increases.

1.3 distinguish common middleware

characteristic ActiveMQ RabbitMQ RocketMQ kafka
Development language java erlang java scala
Stand-alone Throughput Ten thousand Ten thousand 100 000 100 000
Timeliness ms level Class us ms level ms level within
Availability High (master-slave architecture) High (master-slave architecture) Very high (distributed architecture) Very high (distributed architecture)
Features Mature product, many companies applied; there are more documents; better support a variety of protocols Based on erlang development, so the concurrent competence, performance is extremely good, low latency; rich management interface MQ function relatively complete, scalable good MQ supports only the main features, like some message queries, and so did not provide a message back, after all the data is ready for the big, wide application in the field of big data.

2.Btree and B + tree difference?

2.1 Btree

Here Insert Picture Description

2.2 B+tree

B + Tree is an optimization based on the B-Tree to make it more suitable for implementing the external memory index structure, InnoDB storage engine is to use a B + Tree index implemented its structure.
Here Insert Picture Description

We can see not only the key values ​​in each node contains data, and data value from the B-Tree in a configuration diagram in the upper. Each of the memory page is limited, if the data will result in large data for each node (i.e., a page) can store a small number of key, when a large amount of data stored will also lead to B- Tree of greater depth, increasing the disk when I query / O times, thereby affecting the query efficiency. In the B + Tree, all the nodes are in accordance with the key-data records stored in the order of the leaf nodes of the same level, not only stores the key value of the leaf node information, which can greatly increase the number of key values ​​stored at each node reduced height + Tree B.

2.3 B + Tree with respect to the B-Tree have different points:

  • 1. The non-leaf node stores only key information.
  • 2 has a chain of pointers between all leaf nodes.
  • 3. Data records are stored in the leaf node.

3.FastDFS safety, what had been done? For example, people know after pictures or video address to access resources directly.

3.1 FDFS file synchronization, and security settings

A, tracker.conf

#这是前提,表示这个配置不禁用(也就是启用)
disabled=false
 
#数据存放路径:必需配置并且保证目录存在。
base_path=/root/fdfs
 
#允许连接的storage端IP,测试时候可以allow_hosts=*,正式使用为了安全需要填写指定IP(可多个)
allow_hosts=127.0.0.6
allow_hosts=127.0.0.8

二、storage.conf

#这是前提,表示这个配置不禁用(也就是启用)
disabled=false
 
#组名,重要!连接到同一tracker下storage,相同的group_name数据会互相同步,不相同的不会同步。
group_name=group1
 
#数据存放路径:必需配置并且保证目录存在。
base_path=/root/fdfs
 
#未知和base_path作用区别,设置成和base_path相同吧,这样只有好处没有坏处。
store_path0=/root/fdfs
 
#连接的tracker服务器(可多个),需要填写真实的IP:Port(本地写127.0.0.1:Port也不行),需要tracker服务器配置的allow_hosts允许本storage机器的IP
tracker_server=127.0.0.11:22122
tracker_server=127.0.0.12:22122
 
#暂时没有测试,不知其作用,猜测是允许哪个IP来增删文件
allow_hosts=*

4. know and used design patterns? (21 kinds)

Create Type: Simple factory pattern, abstract factory model, the builder pattern, prototype model, singleton
structural: the adapter mode, the appearance model, Flyweight, modified mode, proxy mode, the model view controller mode
behavioral: Dictionary mode, mode status, observer pattern, strategy pattern, template mode, the chain of responsibility pattern, command mode

5. talk about serialization and de-serialization?

5.1 serialization and deserialization defined

Serialization : is not transmitted to an object to be converted may be stored or transmitted during
deserialization : that converts the data on the disk, in a medium such as an object

5.2 python serialized usually in two ways: pickle module and module json

  • Use the pickle module: For most applications in terms of the use of the function dump () and load () is what you use pickle
    module required for all the. Two are different without s is (trans) about the sequence of binary files with s is (trans) about the serialized object
dumps(object)和dump(object) # 序列化
loads(bytes)和load(bytes)# 反序列化
# pickle.dump和pickle.load的使用:序列和反序列化到文件中的
  • Json module used: s without method is used in the document file
json.dumps # 从字典(可序列化json的对象)转换为json格式数据
json.loads # 从json到字典
json.dump
json.load

6.python memory management mechanism?

  • (1) Garbage collection

  • (2) reference count

  • (3) memory pool mechanism

Reference: https://www.cnblogs.com/geaozhang/p/7111961.html

7.redis Affairs

    1. The concept Redis transaction:
        the nature of Redis transaction is a set of commands . Transaction support a multiple commands, all the commands in a transaction will be serialized. During the transaction, the transaction will not be inserted into the request command sequence execution command in the order of serial execution command queue, submitted by other clients.

Concluded: redis affairs is to perform a one-time, sequence, an exclusive series of commands in a queue.

  • 2.Redis no concept of transaction isolation levels:

Batch operation is placed in the queue before sending EXEC command cache and not the actual execution, the query within a transaction does not exist to see the update transaction in the foreign affairs inquiry can not see.

  • 3.Redis does not guarantee atomicity:
      the Redis, a single atomic command is executed, but does not guarantee atomic transaction, and no rollback. Affairs of any command fails, the rest of the command will be executed.

  • Three stages 4.Redis affairs:

Begin transaction
command into the team
executed the transaction

Reference: https://www.cnblogs.com/DeepInThought/p/10720132.html

Published 146 original articles · won praise 66 · views 50000 +

Guess you like

Origin blog.csdn.net/qq_38923792/article/details/96979990