Architect interview bits and pieces

https://blog.csdn.net/JasonDing1354/article/details/45641811?ops_request_misc=%7B%22request%5Fid%22%3A%22158194177519724839229345%22%2C%22scm%22%3A%2220140713.130056874..%22%7D&request_id=158194177519724839229345&biz_id=0&utm_source=distribute.pc_search_result.none-task

 

TCP protocol and UDP protocol What is the difference

TCP (Tranfer Control Protocol) acronym, is a connection-oriented transport protocol to ensure that, before transmitting the data stream, the two sides will first establish a virtual communication channel. Can rarely error-free transmission of data.

Acronym UDP (User DataGram Protocol), which is a connectionless protocol, UDP is used to transfer data, each data segment is an independent information, including the full source and destination on the network to any possible reached the destination path, therefore, you can reach the destination, and the time and completeness of the contents reach a destination can not be guaranteed.

So TCP UDP will be more time to establish the connection. For relatively UDP, TCP has a higher level of security and reliability.

Size of the TCP transport protocol is not limited, once the connection is established, both large amount of data can be transmitted according to a certain format, while UDP is an unreliable protocol, the size is limited, can not exceed 64K per

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For example --- real existence of "two people on the line in order to quickly and easily talk about war on the use of QQ transmission line, resulting in data loss of data on line failure

 

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Open source agreement

GPL (GNU General Public License): GNU General Public License

LGPL (GNU Lesser General Public License): GNU Lesser General Public License

BSD

(Berkeley Software Distribution): Berkeley Software Distribution License Agreement

MIT (Massachusetts Institute of Technology): MIT name from the Massachusetts Institute of Technology

Apache (Apache License): Apache License Agreement

MPL (Mozilla Public License): Mozilla Public License

 

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

"What we are commonly used hash algorithm"

Adder 1. hash: Hash is the so-called additive input element constituting a final result of a combined.

2. Bitwise hash: this type of Hash function by using various bit operation (commonly shift and exclusive-OR) to input sufficient mixing element

3. Multiplication hash: 33 * hash + key.charAt (i)

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

How TCP to ensure reliable transmission? Three-way handshake?

In the TCP connection, the data stream must be served on the other in the correct order. TCP reliability is achieved by a sequence number and acknowledgment (ACK). TCP connection is initialized by a three-way handshake. The purpose of the three-way handshake is connected to both the synchronous serial number and confirmation number and information exchange TCP window size. The first is the client to initiate a connection; represents a second server receives the client's request; represents a third client receives a feedback server.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

 Several methods to achieve thread

(1) Thread class inheritance, override run function

(2) implement Runnable, rewriting run function

(3) implement Callable interface call override function

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

How to call wait () method? If using a block or cycle? why?

wait () method should call the cycle, because when the thread CPU time to get started, and other conditions may not meet, so before treatment, loop detection conditions are satisfied will be better.

wait (), notify () and notifyAll () is a synchronous control method provided in the thread class java.lang.Object for implementing the inter-thread communication. Wait or wake

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

 How to understand the distributed lock?

Because in the daily work, the online server is a distributed deployment of multiple, often faced with solving the distributed data consistency problems at the scene, then they would make use of distributed lock to solve these problems.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

.MYSQL common optimization (sql optimization, optimizing the structure of the table)

SQL optimization, table mechanism optimization, index optimization, parameter optimization cache

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

volatile keyword, Lock

Concurrent programming: atomicity issues, the visibility problem, ordering problem.

volatile keyword can ensure visibility, it can prohibit the instruction word reordering, but can not guarantee atomicity. Visibility can only guarantee that every reading is current value, but no way to guarantee the volatile atomic operations on variables. Lock adding keywords and become a memory barrier in the statement generated.

Lock implementations provide than using synchronized methods and statements available to a wider range of lock operation, it can in a more elegant way to handle thread synchronization issues. With sychronized modified method or block of statements after the code executing the automatic lock release, and we need to use the manual release lock Lock

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Processes and threads:

Process values ​​running program (independence, dynamic, concurrency), the thread refers to the process of implementation of the order flow. The difference is: 1 does not share memory between processes 2. Create the cost of resource allocation processes were much larger, multi-threaded so in highly concurrent environments with high efficiency.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Serialization and de-serialization:

Serialization refers to java objects into a sequence of bytes, opposite deserialization. Java mainly to inter-thread communication, to achieve the object passed. Only Externalizable interface implements the Serializable class object or before being serialized.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Say five new features introduced in JDK 1.8?

Java 8 is a history in the Java open up new versions of JDK 8 in the following five main features:

Lambda expressions; allow anonymous function like an object passing Stream API, take full advantage of modern multi-core CPU, you can write a very simple code; Date and Time API, finally, there is a stable and simple date and time you use extended library available the method, now, there can be static, the default method interface; repeated notes, now you

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

object defines what methods?

clone(), equals(), hashCode(), toString(), notify(), notifyAll(),

wait(), finalize(), getClass()

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

What is the difference .Collection and Collections are?

Collection is a set of Java framework basic interface;

Collections is a tool framework provides a set of Java class, which contains a large number of static methods for collection or return operation.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Described in Java overloading and rewrite?

Overloading and rewrite allow you to use the same name for different functions, but overloading is a compile-time activities, and rewriting is active runtime. You can override methods, but can only override methods in a subclass in the same class. Rewrite must have inherited

Rewriting: 1, in a subclass can be rewritten to the methods inherited from the base class to needed. 2, a method override method is overridden and must have the same method name, return type and parameter list. 3, can not use the overridden method is more stringent than the methods are overridden access.

When overloaded, the method name to be the same, but not the same number and type of parameters, return type may be the same or different. Unable to return typed overloaded function as a distinguishing criterion.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

The difference between String and StringBuilder

1) variable and non-variable: String immutable, each execution of the "+" new situation will create a new object, without frequent changes in the string String, to save memory.

2) whether the multi-thread safe: StringBuilder and no method plus genlock, so not thread-safe. String and StringBuffer are thread-safe.

 

 

Scalability issues

 

Analysis server downtime

Downtime popular point that is server unbearable load, or other reasons such as crash or shutdown condition. Downtime how to read? Its Pinyin dangji, there are people called down machine, crashes, freezes or even directly say so like to understand more. What are the common causes of downtime usually have?

  1, objective reasons server environment. For example, the server room power outage caused by power outages, the room temperature is too high, resulting in server crashes, shutdown. However, this rarely happens in general, because, like Ding Feng new exchange BGP engine room and other data center, usually have good preventive measures, such as spare circuits, backup generators, full-time mechanical refrigeration and natural, can only thermostat system.

  2, server unbearable load. This situation is the main reason for the more common, site traffic surge, the program poisoning, suffered large-scale high consumption of server resources attacks, which led to the depletion of server resources can not load, and ultimately unable to respond to crashes.

  3, the application is unreasonable. For example, a very common phenomenon is due to consider the costs, some owners often hire low configuration of VPS, cloud server, etc., used to build the site, but there is no software to install and many other large construction-related websites at the same time, let server for cars can be, take on the load of large trucks, with predictable results, downtime is a commonplace one who should crash.

  Of course, a common cause of downtime, there are many details reasons, such as improper environment configuration, caught in an infinite loop error in the program, the database indexes missing, the database will be lost and so they waste a lot of server CPU, memory and other resources, thereby resulting in server crashes downtime and so on. However, the most fundamental reason for downtime is not a common cause of these three categories. In addition to multi-server downtime prevention and monitoring based.

Database optimization

1, do not use sub-query sql statement, such as delete from user where uid not in ( select id from order), because the use of sub-query the database to create a temporary table in memory, consumption of resources, if there are two tables and is often associated with a call, it is best to establish another table in a foreign key table with a join statement queries, such as: the Delete from the User left join the Order oN user.id = order.uid;
2, SQL statement is best not to appear "* "instead of a known field, even if you want to query all the fields have to write every field, because the field with a * instead of a database table must first check out what fields and then query the sql statement, virtually without the addition of a significance of inquiries;

3, reasonable index

      3.1 index can speed up a very large extent the database retrieval speed, appearing especially in the where and join the columns or use Order by sorting when the speed is much faster (need to judge or compare or sort of time);

       3.2 However, indexing is not possible, the index will cause too much redundant, because every delete, update, add will refresh the index, the index too many other operations resulting in excessive consumption of resources, too small tables did not need indexing, no one has ever seen on leaflets as well as a directory of two bar.

The second important thing is the table structure optimization, also in this regard are the following brief summary:

        1. select the most appropriate field properties, there may be used a minimum data type of data, such as postal code, phone number of such numbers may be fixed length char (6), char (11); determining whether the gender or sexual text can tinyint; attribute field is not null as possible so not determined whether the air, a reducing step (nULL expression you want to express in other ways, such as -1); If we use this type of text, preferably by sub-table storage;

        2. General information and is not commonly used to store information points table, such as a mall site user table, the user's nickname, avatar, password, user login account of these fields will be used and the user's interests and hobbies, and favorite color this field is stored on the score sheet, I believe that personal information might also Jingdong account opened at the time of registration, after it had made no note of it

 

Refactoring

[Definition] code refactoring
  understanding of the code refactoring: the premise does not change the functional properties of software systems / modules included, follow / use of certain rules, it tends to improve the internal structure. Its value lies in the software life cycle mainly maintainability and scalability.

[] Code refactoring time
  depending on the size of the reconstruction of the impact of the field, we were sequentially described from system-level functions and interface level.

System-level reconstruction
  1. more bloated system, business call link staggered complex, difficult to perform normal maintenance;
  2. The new features add significant costs, expansion difficult;
  3. System technology infrastructure can not meet the business development needs, such as performance bottlenecks frequent, can not quickly add new business logic / modification;
  4. head of the new office, and need for legislation Flag;
API-level reconstruction
  1. poorly designed function declaration:
      a function name is not standardized, the lack of comments, especially yes. function function, a return value and parameters described;
      . B input parameters and the output parameter can not be clearly distinguished;
      . C imprecise parameter types, such as integers and floating-point type;
      . D excessive number of parameters, greater than 5;
      . E parameter unreasonable transfer mode, such as the transmission and passed by reference value;
  some problems 2. functions implemented:
      . a variable ambiguities, unused variables, uninitialized variable, improper initialized;
      B too many lines of code. , such as C language function in terms of a single body of more than 500 lines of code lines, even rows 1000;
      C complex expressions;.
      D algorithm logic: failure scenarios based on reasonable complexity space-time equalization Heteroaryl degree;
      E excessive external dependencies, resulting in an increase in the length of the interface call;.
      . F was repeated a large number of code blocks;
      . G irrational use of global variables, macros, inline functions;
      . H fuzzy boundary interface functions;
[Code rules reconstruction]

System level reconstruction regulation
is simple: the complexity of the recognition system (high availability, high performance, the IO-intensive, the CPU-intensive, application objects), and then employed as suitable and simple architecture;
apply: based on their current and future business characteristics and development trends for technical architecture selection;
evolution: technology architecture is dynamic, ever-changing as the business development improved;
performance optimization throughout the system design has always been: reference blog post "system performance optimization strategy - continued optimization update"
API level reconstruction regulation
reasonable statement;
duty single;
Richter replacement;
high cohesion and low coupling;
object-oriented programming; failure-oriented programming;
maintainability, scalability
[a few notes on the reconstruction of the system on-line]
      a new system or a new API on-line will inevitably introduced unknown or difficult to assess before the test (the test unit testing integrated +) to cover the hard error. In order to ensure second-level rollback when problems arise online, we generally need to be successful version of a previous service as a service of the upgrade downgrade.
5. Compliance gray publish principles: the old API as the default logic, the logic of the new API as downgrading the old API, using tactics divert part of the traffic to the new API.
6. After a period of time to verify, there is no problem if the new API, a new API will be set as the default logic, the old API reserved for downgrade logic.
 

General architects should be how to control migration technology solutions

 

https://blog.csdn.net/qq_16605855/article/details/80966363


 

 

 

 

 

Published 316 original articles · won praise 33 · views 210 000 +

Guess you like

Origin blog.csdn.net/yz18931904/article/details/104367583