I originally scheduled an interview at three o'clock, but the interviewer came online early and saw that I was online, so he told me to start early.
Why use the index of MySQL
B-tree without using skip list? Redis
Why use a skip table instead of a B-tree or binary tree? Rookie’s answer:
Hello interviewer, my name is Zhang San, from Henan. I graduated from XX University. I have been engaged in java development since I graduated in XX. It's been 3 years. Come to your company for an interview and seek a java development job.
A few points to introduce yourself: Who are you and what are your strengths? What have you done all these years? What awards did you win at school? What technologies have you conducted in-depth research on? Is there a design for a highly concurrent system? Have you participated in any large-scale projects?
In short, show off all your assets and let others know which areas you are relatively strong in.
This question actually varies from person to person. For those who are just getting started, call him Building a project feels very challenging.
For Daniel, the “challenge” is no longer technology. What's more, how to package the project to persuade the boss, and how to squeeze one's subordinates are the challenging aspects of the project.
In the interview process, "challenging" is a standard for interviewers. If the interviewer has never been exposed to the technical aspects of the project business and it sounds difficult, then this is a "challenging" project.
If the interviewer is familiar with the challenge project you mentioned, it may be an opportunity and a challenge for you at this time. Answer the questions that the interviewer has not encountered and how you have solved them. Then the interviewer I completely admire you. On the contrary, if the interviewer asks you questions about this project that he knows and you can't answer, then the interview will be greatly compromised.
For example: Five or six years ago, your technology stack included dubbo and Spring Boot, which were very popular, but now they are standard.
However, there are still few developers with experience in big data, high concurrency, and architecture transformation, because most companies cannot develop into large companies. but. This is something that cannot be changed no matter how software engineering develops.
So challenging projects have the following characteristics:
1. Large data volume
2. High concurrency
3. Architecture transformation
As long as your project can have something to do with these things, then your project level will be at least one level higher.
Here, I will give you an answer template:
1. I am responsible for this xxx business project, and this business is for xxx.
2. In order to quickly trial and error and respond to the market quickly, a simple xxxx plan was used in the early stage.
3. With the development of business, this plan has xxx technical problems in xxx.
4. In order to solve these technical difficulties, we finally used the xxx solution, and then introduced these solutions and how these solutions solved these technical problems.
Just tell the truth about your learning process, but be careful, learning should reflect your Actively, in addition, there is a good habit of marking yourself: taking notes, several times is not as good as a bad pen.
It is recommended to read the official website, read books, and watch videos.
In the learning process, keep practicing, constantly reflecting, and constantly summarizing.
Interface>Abstract class>Implementation class
. We can answer from five aspects:
Is the thread safe: HashMap is non-thread safe, HashTable is thread safe . Because the internal methods of HashTable are basically modified by synchronized. (If you want to ensure thread safety, use ConcurrentHashMap);
Efficiency: Because of thread safety issues, HashMap is slightly more efficient than HashTable. In addition, HashTable is basically eliminated, do not use it in your code;
Support for Null key and Null value: HashMap can store null keys and values. But there can only be one null as a key, and there can be multiple nulls as a value; HashTable does not allow null keys and null values, otherwise a NullPointerException will be thrown.
The difference between the initial capacity and the capacity expansion each time:
① If the initial value of the capacity is not specified when creating it, the default initial size of the Hashtable is 11. After each expansion, the capacity becomes the original 2n 1. The default initialization size of HashMap is 16. Each subsequent expansion will double the capacity.
② If the initial value of capacity is given when creating, Hashtable will directly use the size you gave, and HashMap will expand it to a power of 2 (tableSizeFor( in HashMap) )
method guarantee).
Underlying data structure: HashMap after JDK1.8 has undergone major changes in resolving hash conflicts. When the length of the linked list is greater than the threshold (default is 8 ) (it will be judged before converting the linked list into a red-black tree. If the length of the current array is greater than 64, it will choose to expand the array first instead of converting it to a red-black tree). When converting the linked list into a red-black tree, the linked list will be converted into a red-black tree to reduce Search time. Hashtable has no such mechanism.
Although it is an ordinary interview question, many students still do not answer it well during the interview. The nth power of 2 is mentioned in the answer. The interviewer is likely to continue to ask related questions. If it is still unclear, it is recommended to study HashMap systematically.
I have posted two articles before on my blog:
HashMap
The process of adding an element HashMap
The process of adding elements in put can be divided into the following 9 steps:
putVal()
methodYou can read the blog post on my blog: Three years of essential HashMap source code: http://www.woaijava.cc/blog/211
Red Black Tree (Red Black Tree) is a specialized AVL tree (balanced binary tree), which maintains the binary value through specific operations during insertion and deletion operations. Balance the search tree to achieve higher search performance.
There are 5 characteristics of red-black trees:
The nodes are red or black.
The root node is black.
All leaves are black (leaves are NIL nodes)
The two child nodes of each red node are black. (There cannot be two consecutive red nodes on all paths from each leaf to the root)
From any node to each of its leaves All paths contain the same number of black nodes.
#In fact, this question is not difficult. It is rare that some interviewers may ask about the operation of red-black trees, rotating left and right..., I have interviewed There are hundreds of people, but only a few can speak out.
The B tree has two characteristics:
B Trees are generally 1 lane and 3 layers.
InnoDB page sizeThe default is 16KB:
16KB/(4B 6B)≈1638
indexesSo, a two-layer B-tree can store: 16*1638=26208
pieces of data; a three-layer B-tree can store: 16*1638*1638=42928704
pieces of data.
Why does the index of MySQL
use B-tree instead of skip table?
B tree is a multi-tree structure. Each node is a 16k data page, which can store more index information, so fans The output is very high. Three layers can store about 2kw of data. That is to say, if you query the data once, if these data pages are all on the disk, you need to query the disk IO
at most three times.
Jump list is a linked list structure, one piece of data is one node. If the bottom layer is to store 2kw
data, and each query must be able to achieve binary search## The effect of #, 2kw is about
2 to the 24th power , so the approximate height of the jump table is around
24th layer . In the worst case, these 24 layers of data will be scattered in different data pages, which means that one data query will require 24 disk IO.
the number of disk IOs is fewer, so the B-tree query is faster.
Forwrite operations, the B-tree needs to split and merge index data pages, and the jump table is inserted independently, and the number of layers is determined based on a random function. There is no overhead of rotation and balance maintenance, so The writing performance of skip table will be better than B-tree.
In fact, MySQL's storage engine can be changed. In the past, mysql 5.5 was myisam, and later it was
innodb. Their underlying indexes all use
B trees. In other words, you can completely build a storage engine with a skip table index and install it in MySQL. In fact, facebook built a
rocksDB storage engine, which uses
jump table. Speaking directly to the conclusion, its writing performance is indeed better than innodb, but reading performance is indeed much worse than innodb. If you are interested, you can see their performance comparison data in References at the end of the article.
Why use a skip table instead of a B-tree or binary tree?
#This question can also be used when asking what SQL optimizations you know.
WHERE
clause, or the columns in the join clause, but not the columns that appear in the SELECT
The column after the keyword. 1. When designing the database and creating the table, consider performance issues. For example, a single table should not have too many fields. It is recommended that it be within 20. The more indexes, the better. It should be based on The query is created in a targeted manner. Consider indexing the columns involved in the WHERE and ORDER BY commands. You can use EXPLAIN to check whether an index or a full table scan is used, select the appropriate data type, select the appropriate index type, etc.
2. You need to pay attention when writing SQL. For example: do not use the entire table for list data. Use LIMIT to paginate. The number of pages should not be too large. You can find slower SQL by turning on the slow query log. , avoid select *, list the fields that need to be found, etc.
3. Storage engine selection, MyISAM is suitable for SELECT-intensive tables, while InnoDB is suitable for INSERT and UPDATE-intensive tables.
4. Sub-database and table, for example: Sub-database Divide a database into multiple ones. It is recommended to separate reading and writing. Really doing sub-database will also bring a lot of trouble. Development costs are not worth the gain! It is not recommended to use, Table splitting is to optimize a large table according to the above process, but the query is still stuck, then divide the table into multiple tables, divide one query into multiple queries, and then The resulting combination is returned to the user. Table splitting is divided into vertical splitting and horizontal splitting, and a certain field is usually used as the splitting item. For example, split into 100 tables based on the id field: the table name is tableName_id 0. However: sub-tables require modification of the source program code, which will bring a lot of work to development and greatly increase development costs. Therefore: it is only suitable for considering the existence of a large amount of data in the early stages of development and doing a good job in sub-table processing, and is not suitable for applications. It would be too expensive to make modifications after it goes online.
5. Hardware upgrade is the simplest method, but the relative cost is also high, so the boss is not willing to do it.
6. Database upgrade, for example: replace the MySQL database with a big data engine to process data, or replace it with Alibaba Cloud POLARDB. POLARDB is a next-generation relational distributed cloud native database developed by Alibaba Cloud. It is 100% compatible with MySQL and storage. The capacity can reach up to 100T, and the performance can be increased up to 6 times that of MySQL.
Method 1: If the tid of table a is self-increasing and continuous, the id of table b is the index. The SQL statement is as follows.
select * from a,b where a.tid = b.id and a.tid>500000 limit 200;
Method 2: If the tid of table a is not continuous, then you need to use a covering index. tid is either the primary key or an auxiliary index, and the id of table b also needs to have an index. The SQL statement is as follows.
select * from b, (select tid from a limit 50000,200) a where b.id = a.tid;
JVM memory structures include: program counter, heap memory, method area and stack (java virtual machine stack and native method stack).
The program counter (Program Counter Register) is a small memory space. Its function can be regarded as a line number indicator of the bytecode executed by the current thread. In the conceptual model of the virtual machine (only a conceptual model, various virtual machines may be implemented in more efficient ways), the bytecode interpreter works by changing the value of this counter to select the next step that needs to be executed. Basic functions such as bytecode instructions, branches, loops, jumps, exception handling, and thread recovery all rely on this counter to complete.
The heap memory is the largest piece of JVM and consists of the young generation and the old generation. The young generation memory is divided into three parts, Eden space, From Survivor space, and To Survivor space. By default, the young generation follows the 8:1:1
is allocated in the ratio;
The method area stores class information, constants, static variables and other data. It is an area shared by threads. To distinguish it from the Java heap, the method area also An alias is Non-Heap (non-heap); the stack is divided into a Java virtual machine stack and a local method stack, which are mainly used for method execution. The method area can be understood as a specification, and its implementation is such as the permanent generation and metaspace.
Java Virtual Machine Stacks (Java Virtual Machine Stacks) are also thread-private, its life cycle is the same as that of the thread. The virtual machine stack describes the memory model of Java method execution: When each method is executed, a stack frame (Stack Frame) will be created at the same time to store information such as local variable tables, operation stacks, dynamic links, method exits, etc. . The process from each method being called until execution is completed corresponds to the process of a stack frame being pushed from the stack to being popped out of the stack in the virtual machine stack.
Native Method Stacks (Native Method Stacks) and the virtual machine stack play very similar roles. The only difference is that the virtual machine stack serves the virtual machine to execute Java methods (that is, bytecode), and The local method stack serves the Native methods used by the virtual machine. The virtual machine specification does not mandate the language, usage, and data structure of methods in the local method stack, so specific virtual machines can implement it freely.
If there is no Survivor, every time the Eden area performs Minor GC, and there is no age limit, the surviving objects will be Sent to the old age. As a result, the old generation is quickly filled up, triggering Major GC (because Major GC is usually accompanied by Minor GC, it can also be regarded as triggering Full GC). The memory space of the old generation is much larger than that of the new generation, and a Full GC takes much longer than a Minor GC.
The interviewer may ask: What are the disadvantages of long execution time?
Frequent Full GC consumes a long time and will affect the execution and response of large programs. speed.
If you increase the old generation space, more surviving objects can fill the old generation. Although the Full GC frequency is reduced, as the old generation space increases, once a Full GC occurs, it will take longer to execute.
If the old generation space is reduced, although the time required for Full GC is reduced, the old generation is quickly filled with surviving objects and the frequency of Full GC increases.
So the purpose of Survivor is to reduce the number of objects sent to the old generation, thereby reducing the occurrence of Full GC. Survivor's pre-screening ensures that only objects that have experienced 16 Minor GCs can survive in the new generation. , will be sent to the old generation.
Some interviewers ask this question politely and don't pay much attention to your answer, because the interview is probably cool at this time.
However, if there is a chance to ask a question, most people still think you are good, and the probability of being admitted is very high, so you still have to answer carefully
No matter what his mentality is, let's behave well. That’s it.
This question may seem dispensable, but it is actually very important. Generally, interviewers do not like people who say "No problem" because they pay great attention to the personality and innovation of employees. ability. Companies don't like job seekers asking questions about personal benefits. If someone asks: Does your company have any training programs for new employees? Can I participate? Or what is your company’s promotion mechanism? The company will welcome you because it shows your passion for learning and your loyalty to the company, as well as your ambition.
The above is the detailed content of SF Technology Interview. For more information, please follow other related articles on the PHP Chinese website!