Before the Offer · Ep 5: Code Doesn't LieOffer 之前 · 第5集:代码不会说谎

Scene still from Before the Offer · Ep 5: Code Doesn't Lie
enaiapp.com
. , .
直接开始吧。写一个函数,并发抓取一组 URL,同时最多只能有 10 个请求在进行。

1 / 13 · 动画跟对白 · 配音跟字幕

0:00 / 2:00

声音

这一句

跟读这一句。录音只在这台设备上,不会上传。

Let's jump in. Write a function that fetches a list of URLs concurrently, with at most ten requests in flight at once.

直接开始吧。写一个函数,并发抓取一组 URL,同时最多只能有 10 个请求在进行。

原句

我的

剧中公司 Lumora Pay 和人物均为虚构。费率、薪资和数字只是示例,不代表真实市场行情,也不保证面试结果或录用。真实面试请换成你自己项目的真实数据。

下一集

评论

用昵称就行,不用登录。评论会马上出现,管理员可以收起。不要留链接或广告。

还没有评论。留一句就行,不用登录。

场景背景

《Offer 之前 · 第5集:代码不会说谎》的英文题目是 Before the Offer · Ep 5: Code Doesn't Lie。场景在远程视频面试 · 武汉 ↔ 旧金山,属于加拿大的求职职场,难度标的是高级。Priya 让 Leo 现场写并发抓取。他先说错,再退一步讲清泄漏、监控和 GC。

这一集有 13 句对白。中文用来知道柜台在办什么,英文用来跟读。先把整句说完,再换一种说法。这里的句子是练习,不代替远程视频面试 · 武汉 ↔ 旧金山当天的人、表格或收费说明。

第 1 句的中文是「直接开始吧。写一个函数,并发抓取一组 URL,同时最多只能有 10 个请求在进行。」。对应英文是 “Let's jump in. Write a function that fetches a list of URLs concurrently, with at most ten requests in flight at once.”。在远程视频面试 · 武汉 ↔ 旧金山用到这一句时,先原句跟读,再确认自己要回答的是时间、证件、金额,还是一个拒绝。

第 2 句的中文是「好的,我边想边说。我会用工作池:固定数量的 goroutine 从一个 channel 里读任务,这样并发数自然就被限制在 10 个。」。对应英文是 “Okay. Let me think out loud. I'll use a worker pool — a fixed number of goroutines reading jobs from a channel. That naturally caps concurrency at ten.”。在远程视频面试 · 武汉 ↔ 旧金山用到这一句时,先原句跟读,再确认自己要回答的是时间、证件、金额,还是一个拒绝。

第 3 句的中文是「好。那如果调用方中途不再读取结果,会怎么样?」。对应英文是 “Okay. Now, what happens if the caller stops reading results halfway?”。在远程视频面试 · 武汉 ↔ 旧金山用到这一句时,先原句跟读,再确认自己要回答的是时间、证件、金额,还是一个拒绝。

第 4 句的中文是「呃……那它就……就会……结束?」。对应英文是 “Uh… then it… it would just… finish?”。在远程视频面试 · 武汉 ↔ 旧金山用到这一句时,先原句跟读,再确认自己要回答的是时间、证件、金额,还是一个拒绝。

第 5 句的中文是「其实,抱歉,我退一步,好好想清楚。」。对应英文是 “Actually — sorry, let me take a step back and think that through properly.”。在远程视频面试 · 武汉 ↔ 旧金山用到这一句时,先原句跟读,再确认自己要回答的是时间、证件、金额,还是一个拒绝。

第 6 句的中文是「不对,它不会结束。如果没有人读 results,每个 worker 都会永远卡在这个发送操作上,这就是 goroutine 泄漏。这个点抓得好。」。对应英文是 “No, it wouldn't finish. If nobody reads from results, every worker blocks forever on that send. That's a goroutine leak. Good catch.”。在远程视频面试 · 武汉 ↔ 旧金山用到这一句时,先原句跟读,再确认自己要回答的是时间、证件、金额,还是一个拒绝。

第 7 句的中文是「要修复的话,我会把发送也变成可取消的:用 select 加上 ctx.Done() 包起来。这样调用方取消 context,所有 goroutine 都能干净地退出。」。对应英文是 “To fix it, I'd make the send cancellable as well — wrap it in a select with ctx.Done(). Then the caller can cancel the context, and every goroutine exits cleanly.”。在远程视频面试 · 武汉 ↔ 旧金山用到这一句时,先原句跟读,再确认自己要回答的是时间、证件、金额,还是一个拒绝。

第 8 句的中文是「好多了。线上你怎么确认没有泄漏?」。对应英文是 “Better. How would you verify there's no leak in production?”。在远程视频面试 · 武汉 ↔ 旧金山用到这一句时,先原句跟读,再确认自己要回答的是时间、证件、金额,还是一个拒绝。

第 9 句的中文是「我会在监控里盯 goroutine 数量,把 runtime.NumGoroutine 导出到 Prometheus。如果它一直往上涨,就用 pprof 抓 goroutine profile,看它们卡在哪里。测试里我会用 Uber 的 goleak。」。对应英文是 “I'd watch the goroutine count in our metrics — runtime.NumGoroutine exported to Prometheus. If it climbs steadily, I'd pull a goroutine profile with pprof to see where they're stuck. In tests, I'd use goleak from Uber.”。在远程视频面试 · 武汉 ↔ 旧金山用到这一句时,先原句跟读,再确认自己要回答的是时间、证件、金额,还是一个拒绝。

第 10 句的中文是「最后一个:某个服务 GC 压力很大,你从哪里入手?」。对应英文是 “And one last one: a service has high GC pressure. Where do you start?”。在远程视频面试 · 武汉 ↔ 旧金山用到这一句时,先原句跟读,再确认自己要回答的是时间、证件、金额,还是一个拒绝。

第 11 句的中文是「先测量。我会抓 heap profile 找出分配最多的地方。常见的优化是用 sync.Pool 复用缓冲区、按合适容量预分配切片、避免没必要的 string 和 []byte 互转。最后才会去调 GOGC 或者设置内存上限。」。对应英文是 “Measure first. I'd take a heap profile to find the hot allocation sites. Common fixes are reusing buffers with sync.Pool, pre-allocating slices with the right capacity, and avoiding unnecessary conversions between strings and byte slices. Only then would I tune GOGC or set a memory limit.”。在远程视频面试 · 武汉 ↔ 旧金山用到这一句时,先原句跟读,再确认自己要回答的是时间、证件、金额,还是一个拒绝。

第 12 句的中文是「刚才你调整得很好。大多数人答错了会硬撑到底。」。对应英文是 “You recovered well back there. Most people double down when they're wrong.”。在远程视频面试 · 武汉 ↔ 旧金山用到这一句时,先原句跟读,再确认自己要回答的是时间、证件、金额,还是一个拒绝。

第 13 句的中文是「明天系统设计,把你最好的白板拿出来。」。对应英文是 “Tomorrow, system design. Bring your best whiteboard.”。在远程视频面试 · 武汉 ↔ 旧金山用到这一句时,先原句跟读,再确认自己要回答的是时间、证件、金额,还是一个拒绝。

关键说法

Let me think out loud

短语 · 我边想边说。

Let me think out loud is listed as 短语. You hear it in "Okay. Let me think out loud. I'll use a worker pool — a fixed number of goroutines reading jobs from a channel. That naturally caps concurrency at ten". Say Let me think out loud inside that whole line, not by itself. It belongs to 远程视频面试 · 武汉 ↔ 旧金山, not to every counter in 加拿大.

requests in flight

短语 · 正在进行中的请求

requests in flight is listed as 短语. You hear it in "Let's jump in. Write a function that fetches a list of URLs concurrently, with at most ten requests in flight at once". Say requests in flight inside that whole line, not by itself. It belongs to 远程视频面试 · 武汉 ↔ 旧金山, not to every counter in 加拿大.

caps concurrency at ten

短语 · 把并发数上限设为 10

caps concurrency at ten is listed as 短语. You hear it in "Okay. Let me think out loud. I'll use a worker pool — a fixed number of goroutines reading jobs from a channel. That naturally caps concurrency at ten". Say caps concurrency at ten inside that whole line, not by itself. It belongs to 远程视频面试 · 武汉 ↔ 旧金山, not to every counter in 加拿大.

Let me take a step back

短语 · 我退一步重新想一下。

Let me take a step back is listed as 短语. You hear it in "Actually — sorry, let me take a step back and think that through properly". Say Let me take a step back inside that whole line, not by itself. Let me take a step back. It belongs to 远程视频面试 · 武汉 ↔ 旧金山, not to every counter in 加拿大.

blocks forever on that send

短语 · 永远卡在发送操作上

blocks forever on that send is listed as 短语. You hear it in "No, it wouldn't finish. If nobody reads from results, every worker blocks forever on that send. That's a goroutine leak. Good catch". Say blocks forever on that send inside that whole line, not by itself. It belongs to 远程视频面试 · 武汉 ↔ 旧金山, not to every counter in 加拿大.

goroutine leak

短语 · goroutine 泄漏

goroutine leak is listed as 短语. You hear it in "No, it wouldn't finish. If nobody reads from results, every worker blocks forever on that send. That's a goroutine leak. Good catch". Say goroutine leak inside that whole line, not by itself. It belongs to 远程视频面试 · 武汉 ↔ 旧金山, not to every counter in 加拿大.

exits cleanly

短语 · 干净地退出

exits cleanly is listed as 短语. You hear it in "To fix it, I'd make the send cancellable as well — wrap it in a select with ctx.Done(). Then the caller can cancel the context, and every goroutine exits cleanly". Say exits cleanly inside that whole line, not by itself. It belongs to 远程视频面试 · 武汉 ↔ 旧金山, not to every counter in 加拿大.

Measure first

短语 · 先测量(再优化)。

Measure first is listed as 短语. You hear it in "Measure first. I'd take a heap profile to find the hot allocation sites. Common fixes are reusing buffers with sync.Pool, pre-allocating slices with the right capacity, and avoiding unnecessary conversions between strings and byte slices. Only then would I tune GOGC or set a memory limit". Say Measure first inside that whole line, not by itself. It belongs to 远程视频面试 · 武汉 ↔ 旧金山, not to every counter in 加拿大.

每一句怎么用

Let's jump in. Write a function that fetches a list of URLs concurrently, with at most ten requests in flight at once.

直接开始吧。写一个函数,并发抓取一组 URL,同时最多只能有 10 个请求在进行。

This two-part line is "Let's jump in. Write a function that fetches a list of URLs concurrently, with at most ten requests in flight at once". The Chinese gloss is 「直接开始吧。写一个函数,并发抓取一组 URL,同时最多只能有 10 个请求在进行。」. Listen for Let's, jump, Write, function, fetches, list, URLs, concurrently, most, requests, flight, once before you answer. The word list marks requests in flight here. Say the whole line in one breath, then stop. Repeat the original once before you try another wording.

常见错误

With "Let's jump in. Write a function that fetches a list of URLs concurrently, with at most ten requests in flight at once", do not swap who is speaking. Say it in the speaker's words, then stop.

还可以怎么说

  • Could I put it this way: Let's jump in. Write a function that fetches a list of URLs concurrently, with at most ten requests in flight at once
  • Let me say that once more: Let's jump in. Write a function that fetches a list of URLs concurrently, with at most ten requests in flight at once
  • The words to keep are Let's jump Write

Okay. Let me think out loud. I'll use a worker pool — a fixed number of goroutines reading jobs from a channel. That naturally caps concurrency at ten.

好的,我边想边说。我会用工作池:固定数量的 goroutine 从一个 channel 里读任务,这样并发数自然就被限制在 10 个。

This two-part line is "Okay. Let me think out loud. I'll use a worker pool — a fixed number of goroutines reading jobs from a channel. That naturally caps concurrency at ten". The Chinese gloss is 「好的,我边想边说。我会用工作池:固定数量的 goroutine 从一个 channel 里读任务,这样并发数自然就被限制在 10 个。」. Listen for Okay, think, loud, I'll, worker, pool, fixed, number, goroutines, reading, jobs, channel, naturally, caps, concurrency before you answer. The word list marks Let me think out loud, caps concurrency at ten here. Say the whole line in one breath, then stop. Repeat the original once before you try another wording.

常见错误

With "Okay. Let me think out loud. I'll use a worker pool — a fixed number of goroutines reading jobs from a channel. That naturally caps concurrency at ten", do not swap who is speaking. Say it in the speaker's words, then stop.

还可以怎么说

  • Could I put it this way: Okay. Let me think out loud. I'll use a worker pool — a fixed number of goroutines reading jobs from a channel. That naturally caps concurrency at ten
  • Let me say that once more: Okay. Let me think out loud. I'll use a worker pool — a fixed number of goroutines reading jobs from a channel. That naturally caps concurrency at ten
  • The words to keep are Okay think loud

Okay. Now, what happens if the caller stops reading results halfway?

好。那如果调用方中途不再读取结果,会怎么样?

This question is "Okay. Now, what happens if the caller stops reading results halfway". The Chinese gloss is 「好。那如果调用方中途不再读取结果,会怎么样?」. Listen for Okay, happens, caller, stops, reading, results, halfway before you answer. No glossary headword sits inside this exact turn. Say the whole line in answer length, then stop. Repeat the original once before you try another wording.

常见错误

With "Okay. Now, what happens if the caller stops reading results halfway", do not answer with a bare yes. Name the detail the question asks about.

还可以怎么说

  • Could I put it this way: Okay. Now, what happens if the caller stops reading results halfway
  • Let me say that once more: Okay. Now, what happens if the caller stops reading results halfway
  • The words to keep are Okay happens caller

Uh… then it… it would just… finish?

呃……那它就……就会……结束?

This question is "Uh… then it… it would just… finish". The Chinese gloss is 「呃……那它就……就会……结束?」. Listen for then, finish before you answer. No glossary headword sits inside this exact turn. Say the whole line in answer length, then stop. Repeat the original once before you try another wording.

常见错误

With "Uh… then it… it would just… finish", do not answer with a bare yes. Name the detail the question asks about.

还可以怎么说

  • Could I put it this way: Uh… then it… it would just… finish
  • Let me say that once more: Uh… then it… it would just… finish
  • The words to keep are then finish

Actually — sorry, let me take a step back and think that through properly.

其实,抱歉,我退一步,好好想清楚。

This statement is "Actually — sorry, let me take a step back and think that through properly". The Chinese gloss is 「其实,抱歉,我退一步,好好想清楚。」. Listen for Actually, sorry, take, step, back, think, through, properly before you answer. The word list marks Let me take a step back here. Say the whole line in one breath, then stop. Repeat the original once before you try another wording.

常见错误

With "Actually — sorry, let me take a step back and think that through properly", do not swap who is speaking. Say it in the speaker's words, then stop.

还可以怎么说

  • Could I put it this way: Actually — sorry, let me take a step back and think that through properly
  • Let me say that once more: Actually — sorry, let me take a step back and think that through properly
  • The words to keep are Actually sorry take

No, it wouldn't finish. If nobody reads from results, every worker blocks forever on that send. That's a goroutine leak. Good catch.

不对,它不会结束。如果没有人读 results,每个 worker 都会永远卡在这个发送操作上,这就是 goroutine 泄漏。这个点抓得好。

This two-part line is "No, it wouldn't finish. If nobody reads from results, every worker blocks forever on that send. That's a goroutine leak. Good catch". The Chinese gloss is 「不对,它不会结束。如果没有人读 results,每个 worker 都会永远卡在这个发送操作上,这就是 goroutine 泄漏。这个点抓得好。」. Listen for wouldn't, finish, nobody, reads, results, every, worker, blocks, forever, send, That's, goroutine, leak, Good, catch before you answer. The word list marks blocks forever on that send, goroutine leak here. Say the whole line in one breath, then stop. Repeat the original once before you try another wording.

常见错误

With "No, it wouldn't finish. If nobody reads from results, every worker blocks forever on that send. That's a goroutine leak. Good catch", do not swap who is speaking. Say it in the speaker's words, then stop.

还可以怎么说

  • Could I put it this way: No, it wouldn't finish. If nobody reads from results, every worker blocks forever on that send. That's a goroutine leak. Good catch
  • Let me say that once more: No, it wouldn't finish. If nobody reads from results, every worker blocks forever on that send. That's a goroutine leak. Good catch
  • The words to keep are wouldn't finish nobody

To fix it, I'd make the send cancellable as well — wrap it in a select with ctx.Done(). Then the caller can cancel the context, and every goroutine exits cleanly.

要修复的话,我会把发送也变成可取消的:用 select 加上 ctx.Done() 包起来。这样调用方取消 context,所有 goroutine 都能干净地退出。

This two-part line is "To fix it, I'd make the send cancellable as well — wrap it in a select with ctx.Done(). Then the caller can cancel the context, and every goroutine exits cleanly". The Chinese gloss is 「要修复的话,我会把发送也变成可取消的:用 select 加上 ctx.Done() 包起来。这样调用方取消 context,所有 goroutine 都能干净地退出。」. Listen for make, send, cancellable, well, wrap, select, Done, Then, caller, cancel, context, every, goroutine, exits, cleanly before you answer. The word list marks exits cleanly here. Say the whole line in one breath, then stop. Repeat the original once before you try another wording.

常见错误

With "To fix it, I'd make the send cancellable as well — wrap it in a select with ctx.Done(). Then the caller can cancel the context, and every goroutine exits cleanly", do not swap who is speaking. Say it in the speaker's words, then stop.

还可以怎么说

  • Could I put it this way: To fix it, I'd make the send cancellable as well — wrap it in a select with ctx.Done(). Then the caller can cancel the context, and every goroutine exits cleanly
  • Let me say that once more: To fix it, I'd make the send cancellable as well — wrap it in a select with ctx.Done(). Then the caller can cancel the context, and every goroutine exits cleanly
  • The words to keep are make send cancellable

Better. How would you verify there's no leak in production?

好多了。线上你怎么确认没有泄漏?

This question is "Better. How would you verify there's no leak in production". The Chinese gloss is 「好多了。线上你怎么确认没有泄漏?」. Listen for Better, verify, there's, leak, production before you answer. No glossary headword sits inside this exact turn. Say the whole line in answer length, then stop. Repeat the original once before you try another wording.

常见错误

With "Better. How would you verify there's no leak in production", do not answer with a bare yes. Name the detail the question asks about.

还可以怎么说

  • Could I put it this way: Better. How would you verify there's no leak in production
  • Let me say that once more: Better. How would you verify there's no leak in production
  • The words to keep are Better verify there's

I'd watch the goroutine count in our metrics — runtime.NumGoroutine exported to Prometheus. If it climbs steadily, I'd pull a goroutine profile with pprof to see where they're stuck. In tests, I'd use goleak from Uber.

我会在监控里盯 goroutine 数量,把 runtime.NumGoroutine 导出到 Prometheus。如果它一直往上涨,就用 pprof 抓 goroutine profile,看它们卡在哪里。测试里我会用 Uber 的 goleak。

This two-part line is "I'd watch the goroutine count in our metrics — runtime.NumGoroutine exported to Prometheus. If it climbs steadily, I'd pull a goroutine profile with pprof to see where they're stuck. In tests, I'd use goleak from Uber". The Chinese gloss is 「我会在监控里盯 goroutine 数量,把 runtime.NumGoroutine 导出到 Prometheus。如果它一直往上涨,就用 pprof 抓 goroutine profile,看它们卡在哪里。测试里我会用 Uber 的 goleak。」. Listen for watch, goroutine, count, metrics, runtime, NumGoroutine, exported, Prometheus, climbs, steadily, pull, profile, pprof, they're, stuck, tests, goleak, Uber before you answer. No glossary headword sits inside this exact turn. Say the whole line in one breath, then stop. Repeat the original once before you try another wording.

常见错误

With "I'd watch the goroutine count in our metrics — runtime.NumGoroutine exported to Prometheus. If it climbs steadily, I'd pull a goroutine profile with pprof to see where they're stuck. In tests, I'd use goleak from Uber", do not swap who is speaking. Say it in the speaker's words, then stop.

还可以怎么说

  • Could I put it this way: I'd watch the goroutine count in our metrics — runtime.NumGoroutine exported to Prometheus. If it climbs steadily, I'd pull a goroutine profile with pprof to see where they're stuck. In tests, I'd use goleak from Uber
  • Let me say that once more: I'd watch the goroutine count in our metrics — runtime.NumGoroutine exported to Prometheus. If it climbs steadily, I'd pull a goroutine profile with pprof to see where they're stuck. In tests, I'd use goleak from Uber
  • The words to keep are watch goroutine count

And one last one: a service has high GC pressure. Where do you start?

最后一个:某个服务 GC 压力很大,你从哪里入手?

This question is "And one last one: a service has high GC pressure. Where do you start". The Chinese gloss is 「最后一个:某个服务 GC 压力很大,你从哪里入手?」. Listen for last, service, high, pressure, start before you answer. No glossary headword sits inside this exact turn. Say the whole line in answer length, then stop. Repeat the original once before you try another wording.

常见错误

With "And one last one: a service has high GC pressure. Where do you start", do not answer with a bare yes. Name the detail the question asks about.

还可以怎么说

  • Could I put it this way: And one last one: a service has high GC pressure. Where do you start
  • Let me say that once more: And one last one: a service has high GC pressure. Where do you start
  • The words to keep are last service high

Measure first. I'd take a heap profile to find the hot allocation sites. Common fixes are reusing buffers with sync.Pool, pre-allocating slices with the right capacity, and avoiding unnecessary conversions between strings and byte slices. Only then would I tune GOGC or set a memory limit.

先测量。我会抓 heap profile 找出分配最多的地方。常见的优化是用 sync.Pool 复用缓冲区、按合适容量预分配切片、避免没必要的 string 和 []byte 互转。最后才会去调 GOGC 或者设置内存上限。

This two-part line is "Measure first. I'd take a heap profile to find the hot allocation sites. Common fixes are reusing buffers with sync.Pool, pre-allocating slices with the right capacity, and avoiding unnecessary conversions between strings and byte slices. Only then would I tune GOGC or set a memory limit". The Chinese gloss is 「先测量。我会抓 heap profile 找出分配最多的地方。常见的优化是用 sync.Pool 复用缓冲区、按合适容量预分配切片、避免没必要的 string 和 []byte 互转。最后才会去调 GOGC 或者设置内存上限。」. Listen for Measure, first, take, heap, profile, find, allocation, sites, Common, fixes, reusing, buffers, sync, Pool, allocating, slices, right, capacity, avoiding, unnecessary, conversions, between, strings, byte, Only, then, tune, GOGC, memory, limit before you answer. The word list marks Measure first here. Say the whole line in one breath, then stop. Repeat the original once before you try another wording.

常见错误

With "Measure first. I'd take a heap profile to find the hot allocation sites. Common fixes are reusing buffers with sync.Pool, pre-allocating slices with the right capacity, and avoiding unnecessary conversions between strings and byte slices. Only then would I tune GOGC or set a memory limit", do not swap who is speaking. Say it in the speaker's words, then stop.

还可以怎么说

  • Could I put it this way: Measure first. I'd take a heap profile to find the hot allocation sites. Common fixes are reusing buffers with sync.Pool, pre-allocating slices with the right capacity, and avoiding unnecessary conversions between strings and byte slices. Only then would I tune GOGC or set a memory limit
  • Let me say that once more: Measure first. I'd take a heap profile to find the hot allocation sites. Common fixes are reusing buffers with sync.Pool, pre-allocating slices with the right capacity, and avoiding unnecessary conversions between strings and byte slices. Only then would I tune GOGC or set a memory limit
  • The words to keep are Measure first take

You recovered well back there. Most people double down when they're wrong.

刚才你调整得很好。大多数人答错了会硬撑到底。

This two-part line is "You recovered well back there. Most people double down when they're wrong". The Chinese gloss is 「刚才你调整得很好。大多数人答错了会硬撑到底。」. Listen for recovered, well, back, Most, people, double, down, they're, wrong before you answer. No glossary headword sits inside this exact turn. Say the whole line in one breath, then stop. Repeat the original once before you try another wording.

常见错误

With "You recovered well back there. Most people double down when they're wrong", do not swap who is speaking. Say it in the speaker's words, then stop.

还可以怎么说

  • Could I put it this way: You recovered well back there. Most people double down when they're wrong
  • Let me say that once more: You recovered well back there. Most people double down when they're wrong
  • The words to keep are recovered well back

Tomorrow, system design. Bring your best whiteboard.

明天系统设计,把你最好的白板拿出来。

This two-part line is "Tomorrow, system design. Bring your best whiteboard". The Chinese gloss is 「明天系统设计,把你最好的白板拿出来。」. Listen for Tomorrow, system, design, Bring, best, whiteboard before you answer. No glossary headword sits inside this exact turn. Say the whole line in one breath, then stop. Repeat the original once before you try another wording.

常见错误

With "Tomorrow, system design. Bring your best whiteboard", do not swap who is speaking. Say it in the speaker's words, then stop.

还可以怎么说

  • Could I put it this way: Tomorrow, system design. Bring your best whiteboard
  • Let me say that once more: Tomorrow, system design. Bring your best whiteboard
  • The words to keep are Tomorrow system design

练习问答

并发上限怎么控制?

The line in Before the Offer · Ep 5: Code Doesn't Lie supports 固定数量的 worker,把同时请求限制在 10 个. It does not support 来一个 URL 就开无限 goroutine, or 一次只请求一个, or 关掉 context 就行. Answer from the sentence you heard, then stop. This check is practice. It is not a score and not a visa result.

没人读 results 时会怎样?

The line in Before the Offer · Ep 5: Code Doesn't Lie supports worker 卡在发送上,造成 goroutine 泄漏. It does not support 函数马上正常结束, or 自动改回 PHP, or 只多打一行日志. Answer from the sentence you heard, then stop. This check is practice. It is not a score and not a visa result.

答错之后他怎么调整?

The line in Before the Offer · Ep 5: Code Doesn't Lie supports 退一步想清楚,再给出修复. It does not support 坚持第一次的答案, or 结束面试, or 把题目交回去. Answer from the sentence you heard, then stop. This check is practice. It is not a score and not a visa result.

GC 压力大时,第一步是?

The line in Before the Offer · Ep 5: Code Doesn't Lie supports 先测量,抓 heap profile. It does not support 马上把 GOGC 调到最小, or 重启机器, or 删掉测试. Answer from the sentence you heard, then stop. This check is practice. It is not a score and not a visa result.

这一集核对的事实

Before the Offer · Ep 5: Code Doesn't Lie is practice set in 远程视频面试 · 武汉 ↔ 旧金山. The synopsis names the errand. The lines do not set a fee, a form, a score, or a visa result. Check the person, the form, or the page you were given that day.

Before the Offer · Ep 5: Code Doesn't Lie

相关指南和场景

远程视频面试 · 武汉 ↔ 旧金山

Priya 让 Leo 现场写并发抓取。他先说错,再退一步讲清泄漏、监控和 GC。 对白是配音,画面是动画。不保证分数、签证或退款。

常见问题

《Offer 之前 · 第5集:代码不会说谎》在练什么?

Priya 让 Leo 现场写并发抓取。他先说错,再退一步讲清泄漏、监控和 GC。

这一集是真人拍摄的吗?

不是。画面是动画,对白是配音。这是练习材料,不承诺分数、签证或任何结果。

台词全文 · Transcript
  1. Let's jump in. Write a function that fetches a list of URLs concurrently, with at most ten requests in flight at once.

    直接开始吧。写一个函数,并发抓取一组 URL,同时最多只能有 10 个请求在进行。

  2. Okay. Let me think out loud. I'll use a worker pool — a fixed number of goroutines reading jobs from a channel. That naturally caps concurrency at ten.

    好的,我边想边说。我会用工作池:固定数量的 goroutine 从一个 channel 里读任务,这样并发数自然就被限制在 10 个。

  3. Okay. Now, what happens if the caller stops reading results halfway?

    好。那如果调用方中途不再读取结果,会怎么样?

  4. Uh… then it… it would just… finish?

    呃……那它就……就会……结束?

  5. Actually — sorry, let me take a step back and think that through properly.

    其实,抱歉,我退一步,好好想清楚。

  6. No, it wouldn't finish. If nobody reads from results, every worker blocks forever on that send. That's a goroutine leak. Good catch.

    不对,它不会结束。如果没有人读 results,每个 worker 都会永远卡在这个发送操作上,这就是 goroutine 泄漏。这个点抓得好。

  7. To fix it, I'd make the send cancellable as well — wrap it in a select with ctx.Done(). Then the caller can cancel the context, and every goroutine exits cleanly.

    要修复的话,我会把发送也变成可取消的:用 select 加上 ctx.Done() 包起来。这样调用方取消 context,所有 goroutine 都能干净地退出。

  8. Better. How would you verify there's no leak in production?

    好多了。线上你怎么确认没有泄漏?

  9. I'd watch the goroutine count in our metrics — runtime.NumGoroutine exported to Prometheus. If it climbs steadily, I'd pull a goroutine profile with pprof to see where they're stuck. In tests, I'd use goleak from Uber.

    我会在监控里盯 goroutine 数量,把 runtime.NumGoroutine 导出到 Prometheus。如果它一直往上涨,就用 pprof 抓 goroutine profile,看它们卡在哪里。测试里我会用 Uber 的 goleak。

  10. And one last one: a service has high GC pressure. Where do you start?

    最后一个:某个服务 GC 压力很大,你从哪里入手?

  11. Measure first. I'd take a heap profile to find the hot allocation sites. Common fixes are reusing buffers with sync.Pool, pre-allocating slices with the right capacity, and avoiding unnecessary conversions between strings and byte slices. Only then would I tune GOGC or set a memory limit.

    先测量。我会抓 heap profile 找出分配最多的地方。常见的优化是用 sync.Pool 复用缓冲区、按合适容量预分配切片、避免没必要的 string 和 []byte 互转。最后才会去调 GOGC 或者设置内存上限。

  12. You recovered well back there. Most people double down when they're wrong.

    刚才你调整得很好。大多数人答错了会硬撑到底。

  13. Tomorrow, system design. Bring your best whiteboard.

    明天系统设计,把你最好的白板拿出来。

这一集的词 · Words
  • Let me think out loudlˈɛt mˈi θˈɪŋk ˈaʊt lˈaʊd我边想边说。
  • requests in flightɹɪkwˈɛsts ɪn flˈaɪt正在进行中的请求
  • caps concurrency at tenkˈæps kəŋkˈɜːɹənsi æt tˈɛn把并发数上限设为 10
  • Let me take a step backlˈɛt mˈi tˈeɪk ə stˈɛp bˈæk我退一步重新想一下。
  • blocks forever on that sendblˈɑks fɚˈɛvɚ ˈɑn ðˈæt sˈɛnd永远卡在发送操作上
  • goroutine leakɡˈoːɹuːtˌiːn lˈiːkgoroutine 泄漏
  • exits cleanlyˈɛɡzɪts klˈinli干净地退出
  • Measure firstmˈɛʒɚ fˈɝst先测量(再优化)。

Before the Offer · Ep 5: Code Doesn't Lie

本集要点 · Notes

English first. 中文对照写在下一行,方便面试前复习。

  • Let me think out loud.

    我边想边说。

  • requests in flight

    正在进行中的请求

  • caps concurrency at ten

    把并发数上限设为 10

  • Let me take a step back.

    我退一步重新想一下。

  • blocks forever on that send

    永远卡在发送操作上

  • goroutine leak

    goroutine 泄漏

  • exits cleanly

    干净地退出

  • Measure first.

    先测量(再优化)。

💡 面试技巧

💡 面试技巧(本剧最重要的一课): 答错不可怕,硬撑才可怕。卡住时用这三步:① 承认:“Actually, let me take a step back.” ② 出声推理,让面试官听到你怎么想;③ 给出修复方案,并感谢对方:“Good catch.” 面试官看重的是你怎么纠错,而不是你从不出错。

现场代码 · Code

func FetchAll(ctx context.Context, urls []string) []Result {
    jobs := make(chan string)
    results := make(chan Result)
    var wg sync.WaitGroup

    for i := 0; i < 10; i++ {
        wg.Add(1)
        go func() {
            defer wg.Done()
            for u := range jobs {
                results <- fetch(ctx, u)
            }
        }()
    }

    go func() {
        defer close(jobs)
        for _, u := range urls {
            select {
            case jobs <- u:
            case <-ctx.Done():
                return
            }
        }
    }()

    go func() { wg.Wait(); close(results) }()

    var out []Result
    for r := range results {
        out = append(out, r)
    }
    return out
}
select {
case results <- fetch(ctx, u):
case <-ctx.Done():
    return
}

下集预告 · Next

🎬 钩子:画面切到第二天早上,Leo 的书桌上,一块小白板中间写着一个数字:“10,000 orders/sec”。