dark time teaching including interview questions 

Flink

1、flink的运行架构

 ref:https://ververica.cn/developers/advanced-tutorial-1-analysis-of-the-core-mechanism-of-runtime/

key: client与yarn、dispather、RM,JM、TM的架构,heartbeat;eager lazy调度;task恢复个数

2、exactly once的实现

ref:https://www.whitewood.me/2018/10/16/Flink-Exactly-Once-%E6%8A%95%E9%80%92%E5%AE%9E%E7%8E%B0%E6%B5%85%E6%9E%90/, https://blog.csdn.net/kisimple/article/details/83998238

key:state的exactly和端到端的exactly once,state(event可以处理多次,但状态只会记录一次),端到端(state是前提,事务,source回滚,sink twoPhaseSinkcommmitFunction 记录了哪些数据是已经正常写入的,未记录的恢复时删除)

3、window的实现机制

ref:http://wuchong.me/blog/2016/05/25/flink-internals-window-mechanism/#

key:time和count、tumbling-sliding-session;window assigner(key为windowID,value为数据)、trigger(每加入一个元素或者到达定时触发,fire触发处理、purge清空窗口)、evictor(驱逐window中过期的数据);session each data is a window,then merge cause interval

4、state的存储与扩容

ref:https://juejin.im/post/5c87dbdbe51d45494c77d607https://ververica.cn/developers/state-management/

key:MemStateBackend+FS+RocksDB;keyedState(groupby、partitionby,mod max parallelism->key group->average)&operatorState(source,mod,parallelism<kafka partition)

5、反压

ref:https://ververica.cn/developers/advanced-tutorial-2-analysis-of-network-flow-control-and-back-pressure/

key:storm(zk、feedback) ,1.5-tcp(ResultPartition(producer),InputGate,LocalBufferPool、NetWorkBufferPool、off-heap-memory,Netty-HighWaterMark-channel-writeable,socket-tcp-windowsize) credit-Based(backlog size->credit size),sink直接撑爆(静态流控)

-- 

6、算子&partition

ref:https://www.lizenghai.com/archives/40627.html 

key:keyby->aggregation->reduce,fold;global、forward、rebalance、rescale、broadcast、keygroup(hash)、shuffle(随机);

7、parallelism

ref: https://www.jianshu.com/p/3598f23031e6

key: api(算子)>env>-p(client)>sys; too small(线程较少,slot(cpu核数)空闲),too much(不能超过slot,且当source partition<parallelism时,分不到data)

8、restart

ref:https://www.jianshu.com/p/22409ccc7905

key:checkpoint开启(前提),flink-conf.yaml or env.setRestartStrategy : 固定延迟(Fixed Delay),故障率(Failure Rate),无(No)

9、分布式缓存

ref:https://www.jianshu.com/p/5753b5f0bd76

key:env.registerCacheFile(),RichFunction(RuntimeContext,open)广播文件,TM本地

 10、watermark

ref:https://www.jianshu.com/p/2e87abfe89ff

key:event time+window->乱序问题,AssignerWithPeriodicWatermarks/Punctuated;window触发(1、watermark_time>window_endtime(表明在这个window内所有的数据都已经到达), 2、window含有数据); lateData->window.getSideOutput 

11、SQL解

ref:https://www.cnblogs.com/029zz010buct/p/10142264.html 未认真阅读

key:1、calcite生成语法树AST,并语法检查;2、calcite逻辑计划;3、基于calcite rule和flink rule optimiezd logic plan;4、logic->physics plan(flink planer/);5、physics plan->execution plan(codegen生成算子代码)

12、内存管理&序列化

ref:https://www.jianshu.com/p/644d430aaa39

key:NetWorkBuffer(TM间网络传数,32Kb 2048)、Memory Manage Pool(Memory Segment 32K)

 

 

Netty

1、tcp和udp的区别

ref:https://zhidao.baidu.com/question/480841430.html

key:tcp(传输控制,有连接,可靠,超时重发),udp(用户数据报,无连接,丢数据,速度快,如ping)

2、tcp的可靠性

ref:https://www.jianshu.com/p/6aac4b2a9fd7

key:header校验和;超时重发(发送端没收到确认,自动重发);window size

3、tcp握手挥手

ref:https://blog.csdn.net/weixin_41863129/article/details/90754555, https://blog.csdn.net/qq_31869107/article/details/81327494

key:握(1.seq=x, 2.ack=x+1 seq=y, 3.ack=y+1 seq=x+1; 第三次握手是为了确认server端,因为前两次只确定了client),挥手(1.FIN=1 seq=x, 2.ack=x+1,seq=y 3.ack=x+1 seq=z, 4.ack=z+1 seq=x+1, server中间的两次是因为第一次只是通知client收到关闭连接的请求了,但可能还有数据没有发送完,继续等待2MSL,才真正关闭)

4、tcp粘包/拆包

ref:https://www.cnblogs.com/hpu001/p/9925573.html

key:基于无界字节流,最大报文长度&缓存区,应用层控制1、header表明消息长度 2、固定消息长度 3、分隔符; udp 16bitheader中标记, netty LineBasedFrameDecoder解析器利用换行符做分割

5、netty粘包/拆包

ref:https://www.jianshu.com/p/7f69969adf3d

key:LineBasedFrameDecoder(换行符),DelimiterBasedFrameDecoder(指定符号),FixedLengthFrameDecoder(固定长度)

6、同步与异步、阻塞与非阻塞的区别

ref:https://www.jianshu.com/p/d5726d7fb1ce

key: 同步异步与被调用方有关,比如A调用B,B是否立刻返回最终结果;阻塞与非阻塞和调用方A有关,A调用了是否一直等待着结果,如果A一发起调用就不管了,先去其他地方玩一会儿,就是非阻塞。

7、网络IO模型

ref:https://www.jianshu.com/p/a95bcb116765

key:老李水壶烧水,阻塞、非阻塞、多路复用、信号驱动、异步IO;select(实时,1024文件描述符,各个平台)、poll(实时差,文件描述符无穷,各个平台)、epoll(就绪列表无需遍历,无穷,linux);

8、BIO、NIO、AIO

ref:https://www.jianshu.com/p/6ea6ea9cbdab

key:read基于两步:1、准备数据 2、从内核拷贝到进程内。 BIO12都是阻塞,NIO1非2阻,AIO12非阻

 9、epoll空轮询bug

ref:https://www.jianshu.com/p/bac1f66ef9c1

key:reason-selector在没有事件到来的情况下(keynum=0)依然被唤醒,导致线程进入死循环,CPU100%;记录selector.select为空的次数,到达一定次数则重构selector

10、netty基本组件

ref:https://www.cnblogs.com/dafanjoy/archive/2018/09/22/9689566.html

key:channel(socket套接字),EventLoop(Group,绑定一个Thread,channel只绑定一个固定的EL),ByteBuf,ChannelPipeline+ChannelHander(链式处理,In=read,out=write)

11、netty服务端与客户端启动流程

ref:https://www.jianshu.com/p/40a2004a531b

key:按照代码来述说

12、netty 线程模型

ref:https://www.jianshu.com/p/738095702b75https://www.cnblogs.com/guos/p/12188495.html

13、zero-copy

ref:https://www.jianshu.com/p/a199ca28e80d

key:OS 1、磁盘到内核缓冲区(read buffer) 2、内核到用户内存缓冲区 3、用户内存到内核socket buffer 4、内核socket buffer到网卡接口的缓冲区, 23去除,netty(1、directbuffer,避免JVM拷贝一份到堆内 2、composite wrap(逻辑合并) slice(逻辑拆分) 3、FileChannel.transferTo=OS) 

 14、内存分配

ref:https://www.jianshu.com/p/8d894e42b6e6

key:Arena(tinySubPagePools small PoolChunkList(qinit(0~25%) q000(1~50%) q025(25~75%) q050(50~75) q075 q100 Chunk(2048*Page(8K subpage)) ))

15、处理耗时任务

ref:https://www.jianshu.com/p/727bbc7454dc

key:业务线程池,1handler中自定义线程池 2在channle中加入线程池

 

Spring

1、BeanFactory 和 ApplicationContext 有什么区别

ref:https://www.jianshu.com/p/fd8e441b98c8

key:A是B的扩展;B是延迟加载,无法检查出未注入的属性,A预加载,故耗费内存;A支持统一的文件访问方式、国际化

2、bean 生命周期

ref:https://www.jianshu.com/p/1dec08d290c1, https://www.jianshu.com/p/b7a07d511c11, https://blog.csdn.net/qq_38526573/article/details/88091702

key:1、实例化(createBeanInstance() InstantiationlAwareBeanPostProcessor before->initializingafter) 2、属性赋值(populate() after value ) 3、初始化(initializing aware) 4、销毁(disposable->destory)

3、IOC

ref:https://www.jianshu.com/p/7908c47b01d9, https://www.jianshu.com/p/ad05cfe7868e

key:底层类作为参数,实现上层控制下层;BeanDefination; BeanDefinitionRegistry的beanDefinitionMap,singletonObjects

4、AOP

ref:https://www.jianshu.com/p/83f45b8ed3a6 

MethodInterceptor

key:JDK动态代理(实现接口-InvocationHandler.newProxyInstance),cglib(继承生成子类-MethodInterceptor.,增强,final不能); 在bean被实例化并初始化之后,通过postProcessAfterInitialization,通过cglib(jdk动态代理),在实际逻辑执行前后插入我们的增强逻辑

5、事务

ref:https://www.jianshu.com/p/d16728e99365, https://www.jianshu.com/p/b39f3191cac8, https://www.jianshu.com/p/0a61ff384d94

key:声明式(@Transcational),配置式;基于数据库的事务-手动提交;内部调用失效 OR 异常未抛出

6、单例是线程安全的吗?

ref:https://blog.csdn.net/u012129558/article/details/77513236

key:singleton->prototype

7、自动装配

ref:https://www.jianshu.com/p/ab3a9e5d1843

key:@autowired  AutowiredAnnotationBeanPostProcessor

 8、设计模式

ref:https://www.jianshu.com/p/77c990a440cb

key:单例,工厂(BeanFactory),代理(AOP)

9、springboot启动过程

ref: https://blog.csdn.net/zlc3323/article/details/100137222

 

JDK

1、ArrayList 和 Vector 的区别

ref:https://www.jianshu.com/p/fc9e3bf03a98

key:线程安全;AL增长1.5倍,V2倍

2、快速失败 (fail-fast) 和安全失败 (fail-safe) 的区别

ref:https://www.jianshu.com/p/ef65e6778957, https://www.cnblogs.com/shamo89/p/6694336.html

key:Concurrent Modification Exception;modCount!=expectedmodCount;CopyOnWriteArrayList,add-Arrays.copy,读写分离:1内存翻倍;2不一致

3、HashMap

ref:https://www.jianshu.com/p/ee0de4c99f87, https://www.jianshu.com/p/e2f75c8cce01

key:max=2^30(因为符号位占一位);不安全(put-持有相同的链表头而覆盖;resize-逆序环形链表,死循环), diff(1.8头插法、8红黑树O(n)->O(logn))

4、HashSet

ref:https://www.jianshu.com/p/30af0f43f20f

key:底层HashMap;重复判断,先HashCode,再equals

5、LinkedHashMap

ref:https://www.jianshu.com/p/8f4f58b4b8ab

key:extends HashMap,双向链表;

6、CurrentHashMap

ref:https://www.jianshu.com/p/a7767e6ff2a2, https://www.jianshu.com/p/dfbe0ebfec95

key:1.7 segment+ReentrantLock+HashEntry     1.8 synchronized+CAS+Node+红黑树,自旋锁

7、Comparable 和 Comparator 接口区别

ref:https://www.jianshu.com/p/0e0d5feb66c5

key:Comparator(外部实现,new class)优先于Comparable(内部实现,修改自身class)

 

 

JVM

1、类加载过程

ref:https://www.jianshu.com/p/05022d0fabaf

key:1加载,2链接(1验证 2准备 3解析) ,3初始化

2、类加载原理

ref:https://www.cnblogs.com/Qian123/p/5707562.html, https://blog.csdn.net/renjingjingya0429/article/details/88525915

key:硬件到内存;1委托 2可见 3单一; Beat(BoostrapClassLoad<-ExtClassLoad<-AppClassLoad)

 3、内存分配

ref:https://www.jianshu.com/p/9f8fa79f37d5

key:共享 方法区(类的信息、静态变量、常量),堆(new 对象实例); 线程独有 Java栈(方法=栈帧(局部变量表、操作数)), 程序计数器,本地方法区

4、GC

ref:https://www.jianshu.com/p/6831d5448065, https://www.jianshu.com/p/173ee9e2cdffhttps://www.cnblogs.com/dmzna/archive/2020/05/18/12913458.html

key:简单的会看下 

5、try finally 与return的爱恨情仇

ref:https://blog.csdn.net/q5706503/article/details/84543406

key:总之,try中的return会放在最后执行,能不能执行就看finally是不是有return了

6、G1 CMS

https://zhuanlan.zhihu.com/p/182835465https://www.cnblogs.com/dmzna/archive/2020/05/18/12913458.html

 

1、CyclicBarrier和CountDownLatch

ref:https://www.jianshu.com/p/bce9f156080f

key:CountDownLatch(AQS,state递减),CyclicBarrier(ReentrantLock condition 递增)