For web system development, NET is also a lot of knowledge points need to learn, although the current Java is the mainstream, the job market is relatively large, but net is also actively embrace open source, big net Core 2 out, this will undoubtedly bring more hope to net developers, well, the following is the knowledge map of their own paintings, To be looking for a job of their own time to comb under, but also hope to bring you a little help, the first painting and in view of their own limited knowledge of the poor painting, Welcome to pat me, I promptly corrected, thank you!
Note: The graph is a total-sub-structure that will unfold for a knowledge point:
(Figure I)
- Distributed-structure diagram:
(Figure II)
- Memcached: Of course, the distributed cache system is not really meaningful, the distribution needs the client's own implementation, features: Key-value mode storage, memory cache, persistence is not supported, communication between multiple server loads is not supported, simple, efficient, weak reliability.
- Redis: Use more when caching, high concurrency (increased throughput) when distributed locking (SETNX mode). Features: Key-value mode storage (binary), cluster, transaction but no transaction rollback function, persistent, strong reliability
- Mongodb:no-sql database, of course, no data structure, can do massive data storage, features: master-slave copy set, cluster, persistent, basic support all data types, flexible and powerful query function;
Algorithms are a powerful tool for solving distributed problems.
- Modulo: Formula a= hash (key)%N A is a hash value, hash function, key is our server IP or name, N is the number of servers, from the formula can be seen visually, when we increase or remove the number of servers will cause most of the failure, if the cache is most of the failure of the hit rate, may lead to Cache Avalanche, in addition to the library, the sub-table can also be used to take the modulus algorithm, because the database can do replication sets or images can be synchronized data, that is, there is no failure of the situation.
- Hash consistent: is a ring linked list, the first hash (key)---key (can be regarded as key-value form) is balanced distribution in the list, the same problem when we dynamically add and remove the server, will dynamically re-load to another key-the server, This ensures that the new request still works, but there will be a loss of local data, the solution is physical redundancy, good data synchronization.
- Network communication-Structure diagram
(Figure III)
- WEBAPI: Based on the rest architecture style, using the HTTP protocol, implemented using the ASP. NET programming model, its common specifications and constraints: 1,urlapi use name, 2, using HTTP behavior to express behavior: get,post,put,delete; 3, the request and Response Convention serialization mode, CONTENT-TYPE,ACCEPT;4, return status code can be consistent with the HTTP return status, such as 200 for success, 500 for service-side exception, 5, non-state can be easily extended, 6, using Hateoas constraints, Provides a URL to the client that returns the URL and behavior of all your resources, and subsequent clients can access the resources based on the links in the response, regardless of how the service side changes, and always transparent to the client, reducing the client's maintenance costs.
- WCF: Using the SOAP protocol, is based on the Rpc-xml specification, using WSDL to describe and define, support http/s, TCP,MSMQ and other communication protocols, define contracts, implement development, client integration methods have a variety, can directly reference services, can inherit ClientBase, Client instances can be created through the ChannelFactory channel factory, which is implemented transparently in the form of client-side proxy mode, with many tricks in the broker: for example, to achieve server load balancing, For example, custom read client WCF-related configuration files and other configurations are decoupled for easy maintenance; Many of the infrastructure implementations within WCF already have many extensibility points, and authentication to clients can be extended using Usernamepassowrdvalidator, which can be authorized to use Iauthorizationpolicy is extended and uses CAs (Code Access securty) and feature technology, global anomaly points can extend Ierrorhandler, and service behavior can extend IServiceBehavior And these extension codes are implemented and can be completed based on configuration;
(Figure IV)
- Data types, which are divided into value types and reference types, value types include int,double,enum,float, and are characterized by invariance; reference types include: String, class, interface, and so on, which in particular indicate that string has invariance, Strng a= "1" and string b= "1" in A and B are pointing to the same reference, and string a= "1" + "2" in the middle actually generated a temporary new object and occupied a certain amount of memory, the proposed use of stringbulider; The conversion of value types and reference types to boxing and unboxing, affecting performance, to minimize the coercion of type conversions, you can use generics for strong-type conventions;
- Collection, List unordered, repeatable, thread unsafe, presence generics, complexity O (n); Dictionary dictionary, key is non-repeatable, thread unsafe, presence generic, find complexity O (1); HashTable dictionary, key is non-repeatable, thread safe, find complexity O ( 1); Of course, there are queue,stack and so on, the general situation has corresponding thread safety set in front plus concurrent, such as concurrentqueue,concurrentdictionary;
- Delegates and events can be internally decoupled, callbacks, broadcasts, but delegates are more flexible, can be passed as function parameters, while events can only be called internally, and of course, the definition of delegates and events is different, the event is based on the definition of the delegate, more emphasis on the message notification.
- Class and interface, polymorphism, encapsulation, inheritance, is the basic object-oriented data and characteristics, through design patterns and design principles can be very clear familiarity with the object-oriented approach, such as 5 principles: open and close principle, single principle, dependency inversion principle, Richter replacement principle, interface isolation principle; its definition is no longer mentioned.
- concurrency-structure diagram
(Figure V)
- There are high concurrency development requirements, first of all to plan your hardware, software architecture, the planning is based on quantitative data, such as PV,QPS, but also to understand the characteristics of the software and what technology, and then through the performance test to assist, such as JMeter, according to test tools, the response time of the overall service, throughput, In addition, the data should be analyzed to see if there is data confusion.
- Cache, mainly to avoid the bottleneck of database Io, and in memory processing, of course, the capacity of the single-machine cache is limited, can be N machines interconnected shared memory, the use of distributed cache, in high concurrency situations, using the cache has a concept that the relevant business operations and code implementation can be completely in the cache operation, Some data can be pre-warmed to the cache, the service can be run directly from the cache to read, the cache data changes after the final synchronization to the database, can be asynchronous + queue for the message to subscribe and send or to use the polling time to extract data from the cache to write to the database, In the design process to pay extra attention to synchronization failure or failure, there should be a retry mechanism, in fact, in the standalone module, independent services, some services concurrency is not high, the data can be directly written to the database, and then cached; Finally, based on the CAP law, if the service is available, and is the capacity partition here is if the use of distributed cache, finally can only be weak consistency, so we design is to solve more than 90% of the problem (of course, if you can solve 99.999% of the problem better), and another 10% can be manually intervened to solve.
- Current limit, high concurrency must not be fully accepted all requests and one-time processing that service has been the possibility of a crash, that can be discarded partial duplicate requests, you can use Nginx to limit the client IP, while high concurrency must have some important data resources will compete, how to maintain data consistency, Using lock mechanism, pessimistic lock can seriously affect performance, but there will be no dirty read, write wrong situation, optimistic lock, there will be dirty reading situation, but can guarantee the data write no problem, generally we use distributed lock, using Redis's setnx feature, Redis is single-threaded, there are transactions, but the transaction does not rollback mechanism, The Redis transaction is the way of the command set, such as Setnx if the key value does not exist, returns true if the key value already exists and returns False if the return false indicates that the request already exists, then the request is discarded directly, in fact Redis's setnx and membcached Add a bit similar, and then use the queue to serialize the request, to the database basic access is not too high, the last database at least the best master-slave mode, to avoid a single failure, the best data redundancy.
- Algorithm, there is a very common way to limit the flow of requests, token barrels, we first apply for access token, and injected into a bucket container, set the maximum token amount of the container, more than the request directly discarded, when the request access to verify the presence of tokens, If there is the normal processing of subsequent business logic and delete token, or directly discard the request, the above algorithm can be implemented using the SETNX + DELETE command in Redis;
- Queue, there is a very mature queue message middleware, where RABBITMQ is more commonly used to support the persistence of messages, to avoid the central service down after the message is lost; Support ACK mechanism, when the consumer is down or other network causes the message is not received, the queue will be re-sent messages, The message is removed from the queue until the consumer confirms that it is received via the Basicack command; the finite-flow mechanism can limit the request by three ways, such as memory size, disk size and upstream traffic size, can be clustered, but each server queue process does not communicate with each other, so clients need to implement distributed, The algorithm can adopt hash consistency;
(Figure VI)
- Encryption, symmetric encryption A=e (key) , B =d (key) a is the post-encryption value, E is the encryption algorithm, key is the key, B is the decrypted value, D is the decryption algorithm, you can see the encryption decryption key is consistent, shared, so as long as Know key, both sides can be encrypted decryption, there are unsafe factors, commonly used symmetric encryption algorithm DES; Digital signature, that is, to encrypt the content of a string (digital Digest), mainly to ensure the integrity of the content and identity authentication, commonly used digital Signature algorithm MD5; asymmetric encryption C=e (Key1), D=d (Key2) C is the post-encryption value, Key1 is the private key, and E is the encryption algorithm , d is the decrypted value, D is the decryption algorithm, Key2 is the public key, you can see that the encryption key used by the decryption, of course, can also private private key decryption, public key encryption, the two sides of the home decryption private key is not public, to ensure a certain security, the common asymmetric encryption algorithm RSA.
- authentication, commonly used technology is the use of token or digital certificate, token can generally be considered as a digital signature; digital certificates can be considered as a (standard specification and resolution of certificates); The non-symmetric encryption used by the client encrypts specific content based on the private key in the certificate. And then sent to the server, the service side through the public key to decrypt the verification authentication, the public number involved in the development of the end and our service side of the two-way authentication is token, but the use of symmetric encryption.
- authorization, Net inside more commonly used and normative mode is RBAC, that is, based on role control authorization, the concrete implementation can be HttpModule + attribute ; HttpModule is a permission instance that initializes and maintains the session for all (typically excluding static resources) requests (threads), and then labels Attribute and permissions on each method that requires authorization Id,attribute The CodeAccessSecurityAttribute can be extended for implementation.
- SSO, generally we have this kind of demand, for example, there are multiple subsystems, we in a system after the successful landing, the other system will share this login state and no more login, or we have a system, but there are many can be used, such as PC side, app side, When the successful landing on a client, the other side or the client immediately automatically quit to avoid multi-terminal operation, so we think of sure to put one end of the successful state to save and be able to share at the multi-port and global access, with this characteristic of the thought of a distributed cache.
- Web back-end framework-structure diagram
(Fig. Seven)
- From the very beginning of the ASP. NET to the current version of MVC3, the development of more flexible and mature, MVC is a model rather than technical implementation, where the specific technology is no longer elaborated, you can focus on some of the more practical advanced features, such as area, Filter and so on.
- SignalR is a real-time framework, that is, proactive notification, client and server based on HTTP to establish a long connection, when the server has a new message can be actively pushed to the client, common client subscriptions can be based on JavaScript, C # Implementation, Android side also called Signala but not used, SignalR internal communication mechanism has 4 kinds, the best is websocket, the client can specify which communication mechanism, generally automatic switching mode, adopt or switch to that communication mode is based on the client's environment, theoretically, the higher the performance of the better.
- Domain-driven design is an architectural pattern, which brings out a set of theories and methods, value objects like C # value type is also invariant, but the value object is a class instance object, this class has 1 or more attributes, for which we must overwrite its equal and GetHashCode To ensure that it is immutable, GetHashCode is used in the dictionary validation, so the insurance also to overwrite, the entity object is unique, each time we end up using different object entities, to avoid inconsistent memory objects, so we need to give a unique identity, that is, also to equal and GetHashCode to overwrite; the aggregation root is a value object and an entity object, an aggregation root can be understood as a domain model, the aggregate root can be annotated by the interface, and the sessions between multiple aggregation roots through domain events, the implementation of domain events generally adopt the publish-subscribe model, Events are labeled by interfaces, and publishers can inject subscribers into containers, which can be implemented using the IOC framework, such as UNITY,AUTOFAC, and then triggered by different event notifications to different subscribers as the event notifies another aggregation root. While it is possible to notice across the network boundary, according to the CAP law, there will be inconsistent data, so using event source to replay events, you can understand the retry mechanism, the event source is best and the current aggregation root in the same transaction, An event replay can be done by another process, while another aggregation root and event Source (such as modifying its state after processing is completed) is preferably in a transaction, which guarantees consistency of the data, and of course there is the possibility of repeated occurrences of the event, and the workaround adds a field identifier that, when the event is sent out, You can mark this identity as a specific state, such as sending, the next time the dispatch will no longer take the event in the send; in high concurrency, it is not recommended to use the transaction with another event Source implementation method is to use the queue; We abstract the operation is nothing but crud, and cud We can abstract into the command is the write operation, R we know is the query is the read operation, and CQRS is the command query responsibility separation, generally used in the read and write separation of the architecture, write operations generally used in the work unit mode, and read operation can be very flexible, can use the native ADO, and read and write operations may have a certain time delay, such as post-write asynchronous processing, read the time may be dirty data, so this delay or request can not delay the specific project to be specifically designed and implemented.
- Multithreading-Structure diagram
(Fig. Eight)
- Why the thread, in order to process stability, a process is dead, can not affect other processes, and why there is a process, in order to stabilize the operating system, can not operate a notepad on the operating system to the whole system to crash; threads are the logical units of a process, and multiple threads have a common CPU. There will be resource competition, in order to ensure that the data is good chaos, to the thread scheduling, every 30 milliseconds to switch, of course there is performance wear and tear in the process of switching, but also for the user experience and system reliability sacrifice a little performance, in our multi-core ERA this performance can also be ignored;
- Thread implementation, NET keyword thread, sub-foreground thread and background thread, through the isbackgournd to mark, generally we all use the background thread is asynchronous, thread sub-priority to handle, in the scheduling process priority high priority processing, Net provides a more rich thread API, For example Sleep,join,abort no longer one by one, thread pool is to solve the thread back and forth loss performance, its main role is the thread reuse, when a thread to complete the task to return to the thread pool, waiting for the next time, sometimes we asynchronously processing data in order to improve performance, The data are grouped, and then placed in different threads to deal with, such as a thread pool has 5 threads, a batch of data has 1000, then each thread processing 200, of course, there may be non-divisible, (modulo), when the thread processing is completed back to the pool to wait for the next task, The thread pool also has deficiencies such as the inability to see the progress of threads in real-time, the inability to give feedback on the execution results, the task is packaged on the basis of the online pool, optimization, and Net also provides a rich API such as Run, Startfactory, Wait,waitall, ContinueWith, etc.;
- Threading mode, there are many patterns can be implemented as a template, single thread is our common thread Chengneiga lock way, multi-threading through lock to ensure data synchronization; Product-customer is the mode of our publication subscription, the producer, the consumer can be multi-threading, The intermediate data container can use a memory list, a database, or a queue; thread-pre-message, the thread pool pattern, where multiple threads perform life-cycle maintenance in the pool; Asyn and Asyn and CallBack are our common task To asynchronously process and take a delegate for callbacks, of course you can also understand the architecture of the higher level;
Hit the hand a little pain, first write to this, the above is their own experience, if there is improper also please advise, thank you.
NET knowledge map