189 8069 5689

面试go语言问题 golang常见面试题

英语面试常问问题有哪些?

一般有这些:

创新互联建站是网站建设专家,致力于互联网品牌建设与网络营销,专业领域包括网站建设、网站设计、电商网站制作开发、成都小程序开发、微信营销、系统平台开发,与其他网站设计及系统开发公司不同,我们的整合解决方案结合了恒基网络品牌建设经验和互联网整合营销的理念,并将策略和执行紧密结合,且不断评估并优化我们的方案,为客户提供全方位的互联网品牌整合方案!

1.家庭,成长环境。

2.教育背景,专业优势,人格魅力。

3 参加或组织过的活动。

4 你对这份工作的认识以及工作态度。

1. What is important to you in a job?

Mention specific rewards other than a paycheck for example, challenge, t

he feeling of accomplishment, and knowing that you have made a contribution.

2. Why do you want to work for this organization?

Cite its reputation, the opportunities it offers, and the working condit

ions. Stress that you want to work for this organization, not just any organ

ization.

3. Why should we employ you?

Point to your academic preparation, job skills, and enthusiasm about working for the firm. Mention your performance in school or previous employment as evidence of your ability to learn and to become productive quickly. If the job involves management responsibilities, refer to past activities as proof of your ability to get along with others and to work as part of a team.

4. If we hire you, how long will you stay with us?

Answer by saying along these lines: "As long as my position here allows me to learn and to advance at a pace with my abilities."

5. Can we offer you a career path?

Reply: "I believe you could, once I know the normal progression within the organization. Can you tell me about it?" The answer may be revealing.

6. What are your greatest strengths?

Give a response like one of the following: "I can see what needs to be done and do it", "I'm wiling to make decisions", "I work well with others," "

I can organize my time efficiently."

7. What are you greatest weakness?

Identify one or two, such as the following:" I tend to drive myself too

hard", " I expect others to perform beyond their capacities", " I like to se

e a job done quickly, and I'm critical if it isn't." Note these weaknesses c

ould also be regarded as desirable qualities. The trick with this question i

s to describe a weakness so that it could also be considered a virtue.

8. What didn't you like about previous jobs you've held?

Discuss the things you didn't like, but avoid making slighting reference

to any of your former employers.

9. How do you spend your leisure time?

Mention a cross section of interests-active and quiet, social and solitary -- rather just one.

10. Are there any weaknesses in your education or experience?

Take stock of your weaknesses before the interview. Practice discussing them in a positive light. You'll find that they are minor when discussed along with all the positive things you have to offer.

11. Where do you want to be five years from now?

Saying that you'd like to be president is unrealistic, yet few employers want people who are content to sit still. You might say, "in five years, I'd like to have my boss's job. " If you can't qualify for your boss's job by then, you may not be the fright candidate.

12. What are your salary expectations?

If you are asked this at the outset, it's best to say, "Why don't we discuss salary after you decide whether I'm right for the job? "But if the interviewer asks this after showing real interest in you, speak up. She or he will probably try to meet your price. If you need a clue about what to ask for, say, " Can you discuss your salary range with me?"

13. What would you do if....?

This question is designed to test your reposes. For example: "What would

you do if your computer broke down during an audit?" Your answer there isn't nearly so important as your approach to the problem. And a calm approach is best. Start by saying, "One thing I might do is ..." Then give several alternative choices.

14. What type of position are you interested in?

Job titles and responsibilities vary from firm to firm . So state your skills instead, such as "I'm good at figure work," and the positions that req

15. Tell me something about yourself.

Say you'll be happy to talk about yourself, and ask what the interviewer

wants to know. If this point is clarified, respond. If not, tell why you feel your skills will contribute to the job and the organization. This question gives you a great opportunity to sell yourself.

16. Do you have any questions about the organization or the job? Employers like a candidate who is interested in the organization. so this is a perfect time to convey your interest and enthusiasm

Q:Can you sell yourself in two minutes? Go for it. (你能在两分钟内自我推荐吗?大胆试试吧!)

A:With my qualifications and experience, I feel I am hardworking, responsible and diligent in any project I undertake. Your organization could benefit from my analytical and interpersonal skills.(依我的资格和经验,我觉得我对所从事的每一个项目都很努力、负责、勤勉。我的分析能力和与人相处的技巧,对贵单位必有价值。)

Q:Give me a summary of your current job description. (对你目前的工作,能否做个概括的说明。)

A:I have been working as a computer programmer for five years. To be specific, I do system analysis, trouble shooting and provide software support. (我干了五年的电脑程序员。具体地说,我做系统分析,解决问题以及软件供应方面的支持。)

Q:Why did you leave your last job?(你为什么离职呢?)

A:Well, I am hoping to get an offer of a better position. If opportunity knocks, I will take it.(我希望能获得一份更好的工作,如果机会来临,我会抓住。)

A:I feel I have reached the "glass ceiling" in my current job. / I feel there is no opportunity for advancement. (我觉得目前的工作,已经达到顶峰,即没有升迁机会。)

Q:How do you rate yourself as a professional?(你如何评估自己是位专业人员呢?)

A:With my strong academic background, I am capable and competent. (凭借我良好的学术背景,我可以胜任自己的工作,而且我认为自己很有竞争力。)

A:With my teaching experience, I am confident that I can relate to students very well. (依我的教学经验,我相信能与学生相处的很好。)

Q:What contribution did you make to your current (previous) organization?(你对目前/从前的工作单位有何贡献?)

A:I have finished three new projects, and I am sure I can apply my experience to this position. (我已经完成三个新项目,我相信我能将我的经验用在这份工作上。)

Q:What do you think you are worth to us?(你怎么认为你对我们有价值呢?)

A:I feel I can make some positive contributions to your company in the future. (我觉得我对贵公司能做些积极性的贡献。)

Q:What make you think you would be a success in this position? (你如何知道你能胜任这份工作?)

A:My graduate school training combined with my internship should qualify me for this particular job. I am sure I will be successful. (我在研究所的训练,加上实习工作,使我适合这份工作。我相信我能成功。)

Q:Are you a multi-tasked individual?(你是一位可以同时承担数项工作的人吗?) or Do you work well under stress or pressure?(你能承受工作上的压力吗?)

A:Yes, I think so.

A:The trait is needed in my current(or previous) position and I know I can handle it well. (这种特点就是我目前(先前)工作所需要的,我知道我能应付自如。)

Q:What is your strongest trait(s)?(你个性上最大的特点是什么?)

A:Helpfulness and caring.(乐于助人和关心他人。)

A:Adaptability and sense of humor.(适应能力和幽默感。)

A:Cheerfulness and friendliness.(乐观和友爱。)

Q:How would your friends or colleagues describe you?(你的朋友或同事怎样形容你?)

A:(pause a few seconds) (稍等几秒钟再答,表示慎重考虑。)

They say Mr. Chen is an honest, hardworking and responsible man who deeply cares for his family and friends. (他们说陈先生是位诚实、工作努力,负责任的人,他对家庭和朋友都很关心。)

A:They say Mr. Chen is a friendly, sensitive, caring and determined person. (他们说陈先生是位很友好、敏感、关心他人和有决心的人。)

Q:What personality traits do you admire?(你欣赏哪种性格的人?)

A:(I admire a person who is) honest, flexible and easy-going. (诚实、不死板而且容易相处的人。)

A:(I like) people who possess the "can do" spirit. (有"实际行动"的人。)

Q:What leadership qualities did you develop as an administrative personnel?

(作为行政人员,你有什么样的领导才能?)

A:I feel that learning how to motivate people and to work together as a team will be the major goal of my leadership. (我觉得学习如何把人们的积极性调动起来,以及如何配合协同的团队精神,是我行政工作的主要目标。)

A:I have refined my management style by using an open-door policy. (我以开放式的政策,改进我的行政管理方式。)

Q:How do you normally handle criticism?(你通常如何处理别人的批评?)

A:Silence is golden. Just don't say anything; otherwise the situation on could become worse. I do, however, accept constructive criticism. (沉默是金。不必说什么,否则情况更糟,不过我会接受建设性的批评。)

A:When we cool off, we will discuss it later. (我会等大家冷静下来再讨论。)

Q:What do you find frustrating in a work situation?(在工作中,什么事令你不高兴?)

A:Sometimes, the narrow-minded people make me frustrated. (胸襟狭窄的人,有时使我泄气。)

A:Minds that are not receptive to new ideas. (不能接受新思想的那些取。)

Q:How do you handle your conflict with your colleagues in your work? (你如何处理与同事在工作中的意见不和?)

A:I will try to present my ideas in a more clear and civilized manner in order to get my points across. (我要以更清楚文明的方式,提出我的看法,使对方了解我的观点。)

Q:How do you handle your failure?(你怎样对待自己的失败?)

A:None of us was born "perfect". I am sure I will be given a second chance to correct my mistake. (我们大家生来都不是十全十美的,我相信我有第二个机会改正我的错误。)

Q:What provide you with a sense of accomplishment. (什么会让你有成就感?)

A:Doing my best job for your company. (为贵公司竭力效劳。)

A:Finishing a project to the best of my ability. (尽我所能,完成一个项目。)

Q:If you had a lot of money to donate, where would you donate it to?Why?(假如你有很多钱可以捐赠,你会捐给什么单位?为什么?)

A:I would donate it to the medical research because I want to do something to help others. (我会捐给医药研究,因为我要为他人做点事。)

A:I prefer to donate it to educational institutions. (我乐意捐给教育机构。)

Q:What is most important in your life right now?(眼下你生活中最重要的是什么?)

A:To get a job in my field is most important to me. (对我来说,能在这个领域找到工作是最重要的。)

A:To secure employment hopefully with your company. (希望能在贵公司任职对我来说最重要。)

Q:What current issues concern you the most?(目前什么事是你最关心的?)

A:The general state of our economy and the impact of China' entry to WTO on our industry. (目前中国经济的总体情况以及中国入世对我们行业的影响。)

Q:How long would you like to stay with this company?(你会在本公司服务多久呢?)

A:I will stay as long as I can continue to learn and to grow in my field. (只要我能在我的行业力继续学习和长进,我就会留在这里。)

Q:Could you project what you would like to be doing five years from now?(你能预料五年后你会做什么吗?)

A:As I have some administrative experience in my last job, I may use my organizational and planning skills in the future.(我在上一个工作中积累了一些行政经验,我将来也许要运用我组织和计划上的经验和技巧。)

A:I hope to demonstrate my ability and talents in my field adequately. (我希望能充分展示我在这个行业的能力和智慧。)

A:Perhaps, an opportunity at a management position would be exciting.(也许有机会,我将会从事管理工作。)

如果不愿正面回答,也可以说:

It would be premature for me to predict this. (现在对此问题的预测,尚嫌过早。)

甚至还可以打趣的说:

Hypothetically speaking, I might be able to do your current job as a director.(或 CEO 或 president)((说不定,我也能做你现在主任的工作呢!)

Q:What range of pay-scale are you interested in?(你喜欢那一种薪水层次标准?)

A:Money is important, but the responsibility that goes along with this job is what interests me the most. (薪水固然重要,但这工作伴随而来的责任更吸引我。)

A:假如你有家眷,可以说:

To be frank and open with you, I like this job, but I have a family to support. (坦白地说,我喜欢这份工作,不过我必须要负担我的家庭。)

【英语面试常见问题集锦】

近日在网上收集了些英文面试的资料,整理出来供大家参阅。求职面试时的"甜言蜜语"

1. What is important to you in a job?

Challenge, the feeling of accomplishment, and knowing that you have made a contribution.

2. Why do you want to work for this organization?

Its reputation, the opportunities it offers, and the working conditions.

3. Why should we employ you? (我们为什么要雇佣你?)

My academic preparation, job skills, and enthusiasm about working for the firm.

4. If we hire you, how long will you stay with us? (你打算跟我们工作多久?)

As long as my position here allows me to learn and to advance at a pace consistent with my

abilities〖职务随能力增长而相应提高〗.

5. What are your greatest strengths〖最大优点〗?

I can see what needs to be done and do it.

I'm willing to make decisions. (能当机立断。)

I work well with others. (我和他人容易共事。)

I can organize my time efficiently.

6. What are your greatest weaknesses〖最大缺点〗?

I tend to drive myself too hard. (我有时对自己要求过于严格。)

I expect others to perform beyond their capacities. (我对别人的能力期望过高。)

I like to see a job done quickly. (我喜欢速战速决。)

●求职面试者的误区●

1. Has a poor personal appearance. (衣着形象不佳。)

2. Is unable to express self clearly; has poor voice, diction〖措辞〗, and grammar.

3. Lacks knowledge or experience.

4. Is not prepared for interview. (对面试无准备。)

5. Has no real interest in job.

6. Lacks planning for career; has no purpose or goals. (对自己的事业没有安排;没有目标和理想。)

7. Lacks enthusiasm; passive and indifferent.

8. Lacks confidence and poise〖沉着;自信〗; is nervous and ill at ease〖心神不宁〗.

9. Shows insufficient evidence of achievement.

10. Overemphasizes money; is interested only in the best dollar offer. (只对最佳报酬感趣。)

11. Has poor scholastic record; just got by.

12. Is unwilling to start at the bottom; expects too much too soon. (不愿从基层干起;要求太多。)

13. Make excuses.

14. Lacks tact〖圆滑;机敏〗.

15. Lacks maturity.

16. Lacks courtesy; is ill mannered.

17. Condemns past employers. (谴责以前的雇主/老板。)

18. Lacks social skills. (缺乏社交能力。)

19. Shows marked dislike for schoolwork. (讨厌功课。)

20. Lacks vitality〖活力;生命力〗.

21. Fails to look interviewer in the eye〖不敢正视〗.

22. Has limp, weak handshake. (握手时软弱无力。)

面试的最后需要做些什么?

关于真正的面试最后要提醒的是:结束面试时要说:“我对这份工作非常感兴趣,我下一步要干些什么?”朋友,你是否在热切地盼望着?如果聘用你,那将是他们的幸运!

One last great tip about the actual interview: Always end the interview with, “I am very interested in the position. What are the next steps to take?” Boy, are you eager? They’d be lucky to have you!

准备好你要提出的问题

在面试结束前,考官会俯身对你说:“你对我有什么问题要问吗?”这时,你必须提出问题。首先,不要急于提问,要显出 你在思考有些问题在问的样子,然后从你事先想的问题中选出一个合适的提问。这里有风个备选问题:

请您说说一个标准的工作日是什么样的。/ 对您来说,在这家公司荼好在哪里?/ 是否有充分机会参加一些讨论会、培训班,以了解公司的方方面面?/ 您为什么加入这家公司?

考官喜欢谈论他们自己,所以这些问题绝对会赢得他们的好感。

Have questions of your own. Toward the end of interview. the interviewer is going to lean into you and say,” Do you have any questions for me? You must have questions. First, don’t rush into your answer. Look as if you are thinking about whether you have any questions and then ask an appropriate one from the list you’ve thought about beforehand. Here is a handful of potential questions:

How would you describe a typical workday?/What is the best part of working at this company for you? /Are there significant opportunities to take seminars, classes to learn more about the different facets of the company?/Why did you join the company?

Interviewers love to talk about themselves, so these questions will win them over every time.

Go 语言 channel 的阻塞问题

Hello,大家好,又见面了!上一遍我们将 channel 相关基础以及使用场景。这一篇,还需要再次进阶理解channel 阻塞问题。以下创建一个chan类型为int,cap 为3。

channel 内部其实是一个环形buf数据结构 ,是一种滑动窗口机制,当make完后,就分配在 Heap 上。

上面,向 chan 发送一条“hello”数据:

如果 G1 发送数据超过指定cap时,会出现什么情况?

看下面实例:

以上会出现什么,chan 缓冲区允许大小为1,如果再往chan仍数据,满了就会被阻塞,那么是如何实现阻塞的呢?当 chan 满时,会进入 gopark,此时 G1 进入一个 waiting 状态,然后会创建一个 sudog 对象,其实就sendq队列,把 200放进去。等 buf 不满的时候,再唤醒放入buf里面。

通过如下源码,你会更加清晰:

上面,从 chan 获取数据:

Go 语言核心思想:“Do not communicate by sharing memory; instead, share memory by communicating.” 你可以看看这本书名叫:Effective Go

如果接收者,接收一个空对象,也会发生什么情况?

代码示例 :

也会报错如下:

上面,从 chan 取出数据,可是没有数据了。此时,它会把 接收者 G2 阻塞掉,也是和G1发送者一样,也会执行 gopark 将状态改为 waiting,不一样的点就是。

正常情况下,接收者G2作为取出数据是去 buf 读取数据的,但现在,buf 为空了,此时,接收者G2会将sudog导出来,因为现在G2已经被阻塞了嘛,会把G2给G,然后将 t := -ch 中变量 t 是在栈上的地址,放进去 elem ,也就是说,只存它的地址指针在sudog里面。

最后, ch - 200 当G1往 chan 添加200这个数据,正常情况是将数据添加到buf里面,然后唤醒 G2 是吧,而现在是将 G1 的添加200数据直接干到刚才G2阻塞的t这里变量里面。

你会认为,这样真的可以吗?想一想,G2 本来就是已经阻塞了,然后我们直接这么干肯定没有什么毛病,而且效率提高了,不需要再次放入buf再取出,这个过程也是需要时间。不然,不得往chan添加数据需要加锁、拷贝、解锁一序列操作,那肯定就慢了,我想Go语言是为了高效及内存使用率的考虑这样设计的。(注意,一般都是在runtime里面完成,不然会出现象安全问题。)

总结 :

chan 类型的特点:chan 如果为空,receiver 接收数据的时候就会阻塞等待,直到 chan 被关闭或者有新的数据到来。有这种个机制,就可以实现 wait/notify 的设计模式。

相关面试题:

面试问题总结(一)Golang

使用go语言的好处: go语言的设计是务实的, go在针对并发上进行了优化, 并且支持大规模高并发, 又由于单一的码格式, 相比于其他语言更具有可读性, 在垃圾回收上比java和Python更有效, 因为他是和程序同时执行的.

1. 进程, 线程, 协程的区别, 协程的优势

2. 讲一下GMP模型(重点)

3. Go的GC, 混合写屏障(重点)

4. go的Slice和数组的区别, slice的扩容原理(重点)

5. 讲一下channel,实现原理(重点)

6. 讲一下Go的Map的实现原理, 是否线程安全, 如何实现安全(重点)

7. new 和 make 的区别

8. 说一下内存逃逸

9. 函数传指针和传值有什么区别

10. goroutine之间的通信方式

11. 测试是怎么做的(单元测试, 压力测试)

12. 堆和栈的区别

golang面试题2之判断字符串中字符是否全都不同

请实现 个算法,确定 个字符串的所有字符【是否全都不同】。这 我们要求【不允

许使 额外的存储结构】。 给定 个string,请返回 个bool值,true代表所有字符全都

不同,false代表存在相同的字符。 保证字符串中的字符为【ASCII字符】。字符串的

度 于等于【3000】。

这 有 个重点,第 个是 ASCII字符 , ASCII字符 字符 共有256个,其中128个是常

字符,可以在键盘上输 。128之后的是键盘上 法找到的。

然后是全部不同,也就是字符串中的字符没有重复的,再次,不准使 额外的储存结

构,且字符串 于等于3000。

如果允许其他额外储存结构,这个题 很好做。如果不允许的话,可以使 golang内置

的 式实现。

通过 strings.Count 函数判断:

使 的是golang内置 法 strings.Count ,可以 来判断在 个字符串中包含

的另外 个字符串的数量

还有不同的方法同样可以实现,你了解吗?

推荐go相关技术 专栏

gRPC-go源码剖析与实战_带你走进gRPC-go的源码世界-CSDN博客

go面试题整理(附带部分自己的解答)

原文:【 】

如果有解答的不对的,麻烦各位在评论写出来~

go的调度原理是基于GMP模型,G代表一个goroutine,不限制数量;M=machine,代表一个线程,最大1万,所有G任务还是在M上执行;P=processor代表一个处理器,每一个允许的M都会绑定一个G,默认与逻辑CPU数量相等(通过runtime.GOMAXPROCS(runtime.NumCPU())设置)。

go调用过程:

可以能,也可以不能。

因为go存在不能使用==判断类型:map、slice,如果struct包含这些类型的字段,则不能比较。

这两种类型也不能作为map的key。

类似栈操作,后进先出。

因为go的return是一个非原子性操作,比如语句 return i ,实际上分两步进行,即将i值存入栈中作为返回值,然后执行跳转,而defer的执行时机正是跳转前,所以说defer执行时还是有机会操作返回值的。

select的case的表达式必须是一个channel类型,所有case都会被求值,求值顺序自上而下,从左至右。如果多个case可以完成,则会随机执行一个case,如果有default分支,则执行default分支语句。如果连default都没有,则select语句会一直阻塞,直到至少有一个IO操作可以进行。

break关键字可跳出select的执行。

goroutine管理、信息传递。context的意思是上下文,在线程、协程中都有这个概念,它指的是程序单元的一个运行状态、现场、快照,包含。context在多个goroutine中是并发安全的。

应用场景:

例子参考:

waitgroup

channel

len:切片的长度,访问时间复杂度为O(1),go的slice底层是对数组的引用。

cap:切片的容量,扩容是以这个值为标准。默认扩容是2倍,当达到1024的长度后,按1.25倍。

扩容:每次扩容slice底层都将先分配新的容量的内存空间,再将老的数组拷贝到新的内存空间,因为这个操作不是并发安全的。所以并发进行append操作,读到内存中的老数组可能为同一个,最终导致append的数据丢失。

共享:slice的底层是对数组的引用,因此如果两个切片引用了同一个数组片段,就会形成共享底层数组。当sliec发生内存的重新分配(如扩容)时,会对共享进行隔断。详细见下面例子:

make([]Type,len,cap)

map的底层是hash table(hmap类型),对key值进行了hash,并将结果的低八位用于确定key/value存在于哪个bucket(bmap类型)。再将高八位与bucket的tophash进行依次比较,确定是否存在。出现hash冲撞时,会通过bucket的overflow指向另一个bucket,形成一个单向链表。每个bucket存储8个键值对。

如果要实现map的顺序读取,需要使用一个slice来存储map的key并按照顺序进行排序。

利用map,如果要求并发安全,就用sync.map

要注意下set中的delete函数需要使用 delete(map) 来实现,但是这个并不会释放内存,除非value也是一个子map。当进行多次delete后,可以使用make来重建map。

使用sync.Map来管理topic,用channel来做队列。

参考:

多路归并法:

pre class="vditor-reset" placeholder="" contenteditable="true" spellcheck="false"p data-block="0"(1)假设有K路a href=""数据流/a,流内部是有序的,且流间同为升序或降序;

/pp data-block="0"(2)首先读取每个流的第一个数,如果已经EOF,pass;

/pp data-block="0"(3)将有效的k(k可能小于K)个数比较,选出最小的那路mink,输出,读取mink的下一个;

/pp data-block="0"(4)直到所有K路都EOF。

/p/pre

假设文件又1个G,内存只有256M,无法将1个G的文件全部读到内存进行排序。

第一步:

可以分为10段读取,每段读取100M的数据并排序好写入硬盘。

假设写入后的文件为A,B,C...10

第二步:

将A,B,C...10的第一个字符拿出来,对这10个字符进行排序,并将结果写入硬盘,同时记录被写入的字符的文件指针P。

第三步:

将刚刚排序好的9个字符再加上从指针P读取到的P+1位数据进行排序,并写入硬盘。

重复二、三步骤。

go文件读写参考:

保证排序前两个相等的数其在序列的前后位置顺序和排序后它们两个的前后位置顺序相同的排序叫稳定排序。

快速排序、希尔排序、堆排序、直接选择排序不是稳定的排序算法。

基数排序、冒泡排序、直接插入排序、折半插入排序、归并排序是稳定的排序算法。

参考:

head只请求页面的首部。多用来判断网页是否被修改和超链接的有效性。

get请求页面信息,并返回实例的主体。

参考:

401:未授权的访问。

403: 拒绝访问。

普通的http连接是客户端连接上服务端,然后结束请求后,由客户端或者服务端进行http连接的关闭。下次再发送请求的时候,客户端再发起一个连接,传送数据,关闭连接。这么个流程反复。但是一旦客户端发送connection:keep-alive头给服务端,且服务端也接受这个keep-alive的话,两边对上暗号,这个连接就可以复用了,一个http处理完之后,另外一个http数据直接从这个连接走了。减少新建和断开TCP连接的消耗。这个可以在Nginx设置,

这个keepalive_timout时间值意味着:一个http产生的tcp连接在传送完最后一个响应后,还需要hold住keepalive_timeout秒后,才开始关闭这个连接。

特别注意TCP层的keep alive和http不是一个意思。TCP的是指:tcp连接建立后,如果客户端很长一段时间不发送消息,当连接很久没有收到报文,tcp会主动发送一个为空的报文(侦测包)给对方,如果对方收到了并且回复了,证明对方还在。如果对方没有报文返回,重试多次之后则确认连接丢失,断开连接。

tcp的keep alive可通过

net.ipv4.tcp_keepalive_intvl = 75 // 当探测没有确认时,重新发送探测的频度。缺省是75秒。

net.ipv4.tcp_keepalive_probes = 9 //在认定连接失效之前,发送多少个TCP的keepalive探测包。缺省值是9。这个值乘以tcp_keepalive_intvl之后决定了,一个连接发送了keepalive之后可以有多少时间没有回应

net.ipv4.tcp_keepalive_time = 7200 //当keepalive起用的时候,TCP发送keepalive消息的频度。缺省是2小时。一般设置为30分钟1800

修改:

可以

tcp是面向连接的,upd是无连接状态的。

udp相比tcp没有建立连接的过程,所以更快,同时也更安全,不容易被攻击。upd没有阻塞控制,因此出现网络阻塞不会使源主机的发送效率降低。upd支持一对多,多对多等,tcp是点对点传输。tcp首部开销20字节,udp8字节。

udp使用场景:视频通话、im聊天等。

time-wait表示客户端等待服务端返回关闭信息的状态,closed_wait表示服务端得知客户端想要关闭连接,进入半关闭状态并返回一段TCP报文。

time-wait作用:

解决办法:

close_wait:

被动关闭,通常是由于客户端忘记关闭tcp连接导致。

根据业务来啊~

重要指标是cardinality(不重复数量),这个数量/总行数如果过小(趋近于0)代表索引基本没意义,比如sex性别这种。

另外查询不要使用select *,根据select的条件+where条件做组合索引,尽量实现覆盖索引,避免回表。

僵尸进程:

即子进程先于父进程退出后,子进程的PCB需要其父进程释放,但是父进程并没有释放子进程的PCB,这样的子进程就称为僵尸进程,僵尸进程实际上是一个已经死掉的进程。

孤儿进程:

一个父进程退出,而它的一个或多个子进程还在运行,那么那些子进程将成为孤儿进程。孤儿进程将被init进程(进程号为1)所收养,并由init进程对它们完成状态收集工作。

子进程死亡需要父进程来处理,那么意味着正常的进程应该是子进程先于父进程死亡。当父进程先于子进程死亡时,子进程死亡时没父进程处理,这个死亡的子进程就是孤儿进程。

但孤儿进程与僵尸进程不同的是,由于父进程已经死亡,系统会帮助父进程回收处理孤儿进程。所以孤儿进程实际上是不占用资源的,因为它终究是被系统回收了。不会像僵尸进程那样占用ID,损害运行系统。

原文链接:

产生死锁的四个必要条件:

(1) 互斥条件:一个资源每次只能被一个进程使用。

(2) 请求与保持条件:一个进程因请求资源而阻塞时,对已获得的资源保持不放。

(3) 不剥夺条件:进程已获得的资源,在末使用完之前,不能强行剥夺。

(4) 循环等待条件:若干进程之间形成一种头尾相接的循环等待资源关系。

避免方法:

端口占用:lsof -i:端口号 或者 nestat

cpu、内存占用:top

发送信号:kill -l 列出所有信号,然后用 kill [信号变化] [进程号]来执行。如kill -9 453。强制杀死453进程

git log:查看提交记录

git diff :查看变更记录

git merge:目标分支改变,而源分支保持原样。优点:保留提交历史,保留分支结构。但会有大量的merge记录

git rebase:将修改拼接到最新,复杂的记录变得优雅,单个操作变得(revert)很简单;缺点:

git revert:反做指定版本,会新生成一个版本

git reset:重置到某个版本,中间版本全部丢失

etcd、Consul

pprof

节省空间(非叶子节点不存储数据,相对b tree的优势),减少I/O次数(节省的空间全部存指针地址,让树变的矮胖),范围查找方便(相对hash的优势)。

explain

其他的见:

runtime2.go 中关于 p 的定义: 其中 runnext 指针决定了下一个要运行的 g,根据英文的注释大致意思是说:

所以当设置 runtime.GOMAXPROCS(1) 时,此时只有一个 P,创建的 g 依次加入 P, 当最后一个即 i==9 时,加入的最后 一个 g 将会继承当前主 goroutinue 的剩余时间片继续执行,所以会先输出 9, 之后再依次执行 P 队列中其它的 g。

方法一:

方法二:

[图片上传失败...(image-4ef445-1594976286098)]

方法1:to_days,返回给的日期从0开始算的天数。

方法2:data_add。向日期添加指定时间间隔

[图片上传失败...(image-b67b10-1594976286098)]


文章题目:面试go语言问题 golang常见面试题
标题URL:http://cdxtjz.cn/article/hpsggi.html

其他资讯