三次握手四次挥手
time_wait状态必须等待多长时间:
2MSL
MSL是Maximum Segment Lifetime英文的缩写,中文可以译为“报文最大生存时间”,他是任何报文在网络上存在的最长时间,超过这个时间报文将被丢弃。因为tcp报文(segment)是ip数据报(datagram)的数据部分,具体称谓请参见《数据在网络各层中的称呼》一文,而ip头中有一个TTL域,TTL是time to live的缩写,中文可以译为“生存时间”,这个生存时间是由源主机设置初始值但不是存的具体时间,而是存储了一个ip数据报可以经过的最大路由数,每经过一个处理他的路由器此值就减1,当此值为0则数据报将被丢弃,同时发送ICMP报文通知源主机。RFC 793中规定MSL为2分钟,实际应用中常用的是30秒,1分钟和2分钟等。
2MSL即两倍的MSL,TCP的TIME_WAIT状态也称为2MSL等待状态,当TCP的一端发起主动关闭,在发出最后一个ACK包后,即第3次握手完成后发送了第四次握手的ACK包后就进入了TIME_WAIT状态,必须在此状态上停留两倍的MSL时间,等待2MSL时间主要目的是怕最后一个ACK包对方没收到,那么对方在超时后将重发第三次握手的FIN包,主动关闭端接到重发的FIN包后可以再发一个ACK应答包。在TIME_WAIT状态时两端的端口不能使用,要等到2MSL时间结束才可继续使用。当连接处于2MSL等待阶段时任何迟到的报文段都将被丢弃。不过在实际应用中可以通过设置SO_REUSEADDR选项达到不必等待2MSL时间结束再使用此端口。
红黑树
B+ 树是一种树数据结构,是一个n叉排序树,每个节点通常有多个孩子,一棵B+树包含根节点、内部节点和叶子节点。根节点可能是一个叶子节点,也可能是一个包含两个或两个以上孩子节点的节点。
B+ 树通常用于数据库和操作系统的文件系统中。NTFS, ReiserFS, NSS, XFS, JFS, ReFS 和BFS等文件系统都在使用B+树作为元数据索引。B+ 树的特点是能够保持数据稳定有序,其插入与修改拥有较稳定的对数时间复杂度。B+ 树元素自底向上插入。
红黑树旋转:
降低左子树的高度,增加右子树的高度
将x变为当前位置的右子节点
mysql隔离级别
事务隔离级别 脏读 不可重复读 幻读
读未提交(read-uncommitted) 是 是 是
不可重复读(read-committed) 否 是 是
可重复读(repeatable-read) 否 否 是
串行化(serializable) 否 否 否
##
快排最坏复杂度O(nlogn) 在最坏的情况下,待排序的序列为正序或者逆序,时间复杂度O(n^2)
JVM内存模型
- 方法区
- 堆区
- 本地方法栈
- 虚拟机栈
- 程序计数器
其中,方法区和堆是所有线程共享的。
1.自我介绍
2.object类里边的方法,hashcode和equals的区别,引申到map,扩容的实现,时间复杂度; HashMap():构造一个具有默认初始容量 (16) 和默认加载因子 (0.75) 的空 HashMap。
初始容量,加载因子。这两个参数是影响HashMap性能的重要参数,其中容量表示哈希表中桶的数量,初始容量是创建哈希表时的容量,加载因子是哈希表在其容量自动增加之前可以达到多满的一种尺度,它衡量的是一个散列表的空间的使用程度,负载因子越大表示散列表的装填程度越高,反之愈小。对于使用链表法的散列表来说,查找一个元素的平均时间是O(1+a),因此如果负载因子越大,对空间的利用更充分,然而后果是查找效率的降低;如果负载因子太小,那么散列表的数据将过于稀疏,对空间造成严重浪费。系统默认负载因子为0.75,一般情况下我们是无需修改的。
HashMap底层实现还是数组,只是数组的每一项都是一条链。其中参数initialCapacity就代表了该数组的长度。HashMap的最大容量值为2^30
//初始化table数组
table = new Entry[capacity];
随着HashMap中元素的数量越来越多,发生碰撞的概率就越来越大,所产生的链表长度就会越来越长,这样势必会影响HashMap的速度,为了保证HashMap的效率,系统必须要在某个临界点进行扩容处理。该临界点在当HashMap中元素的数量等于table数组长度加载因子。但是扩容是一个非常耗时的过程,因为它需要重新计算这些数据在新table数组中的位置并进行复制处理。所以如果我们已经预知HashMap中元素的个数,那么预设元素的个数能够有效的提高HashMap的性能。
线程间共同使用的资源有哪些?
进程间通信需要拷贝哪些数据和资源?File descriptor/+memory space.
Linux中创建进程用fork操作,clone也是产生的新的process。通过ps -ef看到的是进程列表,线程可以通过ps -eLf来查看。
Exception in thread “main” java.lang.OutOfMemoryError: unable to create new native thread
内存太小
在Java中创建一个线程需要消耗一定的栈空间,默认的栈空间是1M(可以根据应用情况指定-Xss参数进行调整),栈空间过小或递归调用过深,可能会出现StackOverflowError。
对于一个进程来说,假设一定量可使用的内存,分配给堆空间的越多,留给栈空间的就越少。这个限制常见于32位Java应用,进程空间4G,用户空间2G(Linux下3G,所以通常堆可以设置更大一些),减去堆空间大小(通过-Xms、-Xmx指定范围),减去非堆空间(其中永久代部分通过PermSize、MaxPermSize指定大小,在Java8换成了MetaSpace,默认不限制大小),再减去虚拟机自身消耗,剩下的就是栈空间,假设剩下300M,那么理论上就限制了只能开300线程。不过对于64位应用,由于进程空间近乎无限大,所以可以不考虑这个问题。
ulimit系统限制
ulimit -a查看系统参数.
1.程序Bug,修改参数是不能解决的
2.程序需要大量线程,线程不足:*在java中, 当创建一个线程的时候,虚拟机会在JVM内存创建一个Thread对象,同时创建一个操作系统线程,而这个系统线程的内存用的不是JVMMemory,而是系统中剩下的内存(MaxProcessMemory - JVMMemory - ReservedOsMemory)。
如果程序确实需要大量的线程,现有的设置不能达到要求,那么可以通过修改MaxProcessMemory,JVMMemory,ThreadStackSize这三个因素,来增加能创建的线程数:
1、-Xmn:设置新生代的大小NewSize和MaxNewSize;
2、-Xms:设置堆的初始值InitialHeapSize,也是堆的最小值;
3、-Xmx:设置堆的最大值MaxHeapSize;
ThreadStackSize定义在globals.hpp中,根据当前系统类型,加载对应的配置文件,所以在不同的系统中,ThreadStackSize的默认值也不同。
3.wait notify ,synchronize方法,
4.不能够创建更多的线程数怎么排查
5.class的加载流程,一段java代码在栈帧中的执行过程
6.写一条sql,执行流程,b树怎么遍历,多少次io,二级索引查数据的流程,看了哪些书
7.volatile关键字的作用,被质疑这个关键字真的有用吗
8.打开文件流写入磁盘的过程,机械磁盘的查找过程
9.kafka 0拷贝机制,socket连接过程,nio和bio的区别
10.设计模式
11.nginx 和 tomcat的原理,优化….
12.linux命令
13.tcp连接数,挥手过程及状态转移
14.怎么学习新技术,对业务和技术的理解
15.股票买卖问题
知道的redis全说出来 redis基于内存的,redis 的 rdb 和 aof, redis有虚拟内存,redis用的跳表。解释了一下aof和rdb 2. 虚拟内存为什么会损耗性能 我回答的是磁盘i/o、错了估计是内存映射 3. redis的瓶颈是什么 我回答单点故障 4. 说一下线程池 巴拉巴拉. 5. 说一下jvm. 6. 好了我们做一下题目 1. max point line 2. 求1000000w以内的素数
Redis瓶颈是单线程,所以一定要避免那种耗时的操作.
有上面分析可知:RDB方式持久化的颗粒比较大,当服务器宕机时,到上次save或bgsave后的所有数据都会丢失。而AOF的持久化颗粒比较细,当服务器宕机后,只有宕机之前没来得AOF的操作数据会丢失。
1.RDB持久化是redis默认的,用来生成某一个时间点的数据快照;RDB是一个经过压缩的二进制文件,采用RDB持久化时服务器只会保存一个RDB文件(维护比较简单);
2.AOF实现:
1)AOF持久化是通过保存redis服务器所执行的写命令来记录数据库状态的;被写入AOF文件的所有命令都是以Redis的命令请求协议格式保存的(Redis的请求协议是纯文本的)。服务器在启动时,通过载入AOF文件、并执行其中的命令来还原服务器状态。
1.Tomcat查看tomcat日志输出
tail -f catalina.out命令实时查看tomcat的输出。查看系统磁盘的空间df
java基础如concurrent包、jvm优化、内存管理、gc分析、hadoop/spark/impala/lucene/RocksDB/redis这些框架的技术点
算法是大数据归并排序、遗传算法
项目是因人而已,我是报的数据库组,问了很多数据库的知识,B+树怎么索引,LSM的技术,分布式一致性算法,分布式事务这些
英文面比较奇葩,面试官打开了我的(https://github.com/jinhang) 聊了下项目内容,真心奇葩啊。
public final class String
extends Object
implements Serializable, Comparable
String不能继承,因为有final,有final不能被继承
StringBuilder more speed up no synchonization; StringBuffer single thread.
2个字符串,找它们都包含的最长子串。
还问了 你如何用程序实现一个图
地图中 2个位置最短的路径用程序如何实现,我说可以用广度优先搜索,他说其它方式呢?
快速排序是怎样的
还问了算法稳定性的含义是?
假定在待排序的记录序列中,存在多个具有相同的关键字的记录,若经过排序,这些记录的相对次序保持不变,即在原序列中,ri=rj,且ri在rj之前,而在排序后的序列中,ri仍在rj之前,则称这种排序算法是稳定的;否则称为不稳定的。
堆排序、快速排序、希尔排序、直接选择排序不是稳定的排序算法,而基数排序、冒泡排序、直接插入排序、折半插入排序、归并排序是稳定的排序算法。
JVM
一是Java的内存分配原理与C/C++不同,C/C++每次采用malloc或new申请内存时都要进行brk和mmap等系统调用,而系统调用发生在内核空间,每次都要中断进行切换,这需要一定的开销,而Java虚拟机是先一次性分配一块较大的空间,然后每次new时都在该空间上进行分配和释放,减少了系统调用的次数,节省了一定的开销,这有点类似于内存池的概念;二是有了这块空间过后,如何进行分配和回收就跟GC机制有关了,然后我详细介绍了GC原理、画图表示年轻代(Eden区和Survival区)、年老代、比例分配及为啥要这样分代回收(我认为巧妙就在于这里),有了GC基本结构后,我又详述了下GC是具体如何进行内存分配和垃圾回收的。
数据库操作和调优
- 熟悉数据库常用操作及调优。
- 熟悉并行计算及分布式计算。
- 熟悉消息队列及其使用。
Spring部分
Spring,详细讲述了它解耦的功能、AOP原理及自己有利用动态代理简单模拟实现过一个简单的AOP功能、IOC(DI)等。
面经2
1.两个文件 里面各存有100G32字节的url 只有4G内存,设计算法判断两个文件重复url..(我说了布隆过滤器和字典树 效果不理想)
2.第三范式的特点和缺陷
3.如何抽象出数据库的表
4.设计阻塞队列(我说了生产者消费者 不满意)
5.jvm的gc 内存划分 内存模型
6.juc架构
7.为什么低版本ReentrantLock在高并发下比synchronized效率高