城市天际线下载_从软件工程师的角度看城市天际线

本文探讨了《城市:天际线》游戏中的城市规划与软件工程中的问题解决策略的相似之处,重点分析了交通问题及其解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

城市天际线下载

不同角度的软件工程 (Software Engineering in different perspectives)

In the last few months, I have been exploring and experiencing (a.k.a playing) Cities: Skylines. For those who are not aware, Cities: Skyline is a simulated city-building video game. Although this game focuses on city planning, I found it interestingly sharing similar problems to what we deal with in Software Engineering.

在过去的几个月中,我一直在探索和体验(又称“玩耍”)“ 城市:天际线” 。 对于那些不知道的人,《 城市:天际线》是一款模拟城市建筑的视频游戏。 尽管该游戏专注于城市规划,但我发现它有趣地与我们在软件工程中遇到的问题共享相似的问题。

In this article, we would be looking at Traffic, the similarities in its impacts, and approaches to solve the problems in both City Planning and Software Engineering. These problems arise due to handling high load while having resource constraints.

在本文中,我们将研究流量,其影响的相似性以及解决城市规划和软件工程中的问题的方法。 这些问题是由于在具有资源限制的同时处理高负载而产生的。

Let me show you how. But, please bear in mind that my knowledge with city planning is limited to exposure to the game and personal casual life experiences.

让我告诉你怎么做。 但是,请记住,我对 城市规划的 知识 仅限于接触游戏和个人休闲生活。

交通 (Traffic)

Traffic unarguably is one of the biggest issues in Cities: Skylines or any cities in the world. The longer the time to get from A to B, the less efficient things can be run in a city.

毫无疑问,交通是城市中最大的问题之一:天际线或世界上任何城市。 从A到B的时间越长,在城市中运行的效率越低。

Image for post

Let’s take the Economy and Healthcare aspects as examples.

让我们以经济医疗保健方面为例。

对经济的影响 (Impacts on the Economy)

If traffic is bad, raw materials cannot be transported in time. This leads to goods that cannot be produced in time. Commercials do not have enough to sell. People do not have enough to buy and consume. The economy collapses.

如果交通不畅,原材料将无法及时运输。 这导致无法及时生产商品。 商业广告没有足够的销量。 人们没有足够的购买和消费。 经济崩溃。

People start leaving the city. POOFS, the city is gone.

人们开始离开这座城市。 POOFS,这座城市不见了。

对医疗保健的影响 (Impacts on Healthcare)

If traffic is bad, it takes longer for ambulances to travel from hospitals to patients and get back. With a limited number of ambulances, longer round trip time means fewer people can reach hospitals.

如果交通不畅,救护车需要更长的时间才能从医院运送到病人并返回。 由于救护车数量有限,往返时间较长,意味着到医院就医的人数会减少。

Imagine there are 10 ambulances in a hospital. If all of them are stuck in traffic jams, no patient would be treated in time.

想象一下,医院里有10辆救护车。 如果所有这些人都被塞在交通拥堵中,则不会及时治疗患者。

Or about deathcare, there are a limited number of hearses in each funeral company to transport the deads. If all of the hearses are stuck in traffic or take a long time to collect the dead, eventually, there would be enough dead bodies lying in buildings making the city unlivable.

关于死亡护理 ,每个fun仪公司都有数量有限的灵车来运送死者。 如果所有的灵车都堵在车里或花费很长时间来收集死者,那么最终,建筑物中就会有足够多的死者尸体,使这座城市无法居住。

People start leaving the city. POOFS, the city is gone.

人们开始离开这座城市。 POOFS,这座城市不见了。

软件工程中的流量问题 (Traffic problems in Software Engineering)

The same challenge applies to software applications too.

同样的挑战也适用于软件应用程序。

The higher the latency in network calls resulted in longer response time to end-users’ requests. Given a limited number of concurrent requests can be served, fewer requests can be handled, and the service would eventually reach denial-of-service (DoS).

网络呼叫的等待时间较长,导致对最终用户请求的响应时间更长。 如果可以处理有限数量的并发请求,则可以处理更少的请求,并且该服务最终将达到拒绝服务(DoS)。

解决交通问题 (Solving the traffic issues)

There is quite a number of patterns we could apply from Software Design into City Planning.

从软件设计到城市规划,我们可以应用许多模式。

But first, to solve traffic problems, we would first need to

但是首先,要解决交通问题,我们首先需要

  • Understand where traffic comes from

    了解流量来自何处
  • Identify hot spots

    识别热点
  • And then solve the problems

    然后解决问题

Let’s start!

开始吧!

流量来源 (The sources of traffic)

在城市规划中 (In city planning)

Image for post

Traffic comes from people going to work or going for entertainment.

交通来自上班或娱乐的人们。

Traffic comes from trucks transporting raw materials to industrial zones, transporting goods from industrial zones to commercial zones.

交通来自将原材料运输到工业区,将货物从工业区运输到商业区的卡车。

Traffic comes from public services like healthcare, deathcare, firetrucks, police cars, …

交通来自医疗保健,死亡护理,救火车,警车等公共服务。

在软件工程中 (In software engineering)

Image for post

Traffic comes from users requesting for webpages, APIs, videos, images, …

流量来自请求网页,API,视频,图像等的用户。

Traffic comes from analytics trackings.

流量来自分析跟踪。

In the context of microservices, besides traffic originated from end-users, there is a large amount of internal traffic happening due to communication between services.

在微服务的上下文中,除了源于最终用户的流量之外,由于服务之间的通信,还会发生大量内部流量

识别热点 (Identify hot spots)

I love making data-driven decisions.

我喜欢制定数据驱动型决策。

It is pretty awesome that Cities: Skylines provides a set of tools for that. You can get more tooling from the modding workshops too.

城市:天际线为此提供了一套工具,这真是太棒了。 您也可以从改装车间获得更多工具。

Image for post
Red areas signifying bad traffic
红色区域表示交通不畅

Looking at the traffic analyzer, we would be able to identify the hot spots that need looking at. Most of the time, they would be industrial or commercial areas where a lot of trucks operating.

查看流量分析器,我们将能够确定需要查看的热点。 在大多数情况下,它们将是在许多卡车在运转的工业商业 区域

You can observe a lot of red areas around intersections, those are places vehicles making turns to their destinations. This means that, if there are a lot of vehicles going to the same destinations, making the same turns, traffic would be bad.

您可以在十字路口周围看到很多红色区域,这些区域是车辆驶向目的地的地方。 这意味着,如果有许多车辆前往相同的目的地,进行相同的转弯,那么交通将会很糟糕。

In software development

在软件开发中

Great toolings would also help make our lives easier.

出色的工具也将使我们的生活更轻松。

Image for post
Example of application monitoring dashboard
应用程序监控仪表板示例

It is crucial to have your endpoints and system metrics monitored. Some of the common tools are SignalFx, Datadog, Prometheus, …

监视端点和系统指标至关重要。 一些常见的工具是SignalFx,Datadog,Prometheus等。

Monitoring would help to identify long-running requests or detect sudden spikes in traffic.

监视将有助于识别长时间运行的请求或检测流量突然增加。

Now let’s talk about some of the ways to solve the traffic problems.

现在让我们讨论一些解决交通问题的方法。

公共交通与批量请求 (Public transport vs. Batch requests)

A bus can transport around 30 people. A metro train can transport around 150 people.

一辆公共汽车可以运送大约30人。 地铁可运送约150人。

Without public transport, those 30–150 people using private vehicles would result in 15–50 times more traffic than a single bus or train.

如果没有公共交通工具,那30-150人使用私家车将导致的交通量是单辆巴士或火车的15-50倍

In software engineering, a similar strategy is applied by batching network requests in larger batch requests. Each request has its own request headers and response headers. Batching requests help minimize bandwidth consumption thanks to avoiding the headers of each individual request.

在软件工程中 ,通过在较大的批处理请求中批处理网络请求来应用类似的策略。 每个请求都有其自己的请求标头和响应标头。 批处理请求避免了每个单独请求的标头,从而有助于最大程度地减少带宽消耗。

It would also help significantly reduce the number of IO calls, i.e. reduce latencies when communicating between services.

这也将有助于大大减少IO调用的数量,即减少服务之间进行通信时的等待时间。

划分高流量区域与分片 (Dividing high traffic zones vs. Sharding)

As explained above, industrial zones are major sources of traffic due to several reasons

如上所述,由于多种原因,工业区是主要的交通来源

  • Trucks delivering raw materials to factories

    卡车运送原料到工厂
  • Trucks delivering produced goods from factories to commercial zones

    卡车将生产的货物从工厂运送到商业区
  • Private vehicles of people coming for work

    上班族的私家车
  • Public services (especially firetrucks as factories being highly prone to fire)

    公共服务(尤其是因为工厂极易起火的救火车)
  • And, trucks are significantly bigger than normal vehicles, occupy more space when queuing, and take a longer time to turn or accelerate

    而且,卡车比普通车辆大得多,排队时占用更多空间,而且转弯或加速所需的时间更长

Therefore, large industrial zones easily cause traffic jams on the main roads in-and-out the areas since even 5-lane-road would not be sufficient to handle such traffic.

因此,大型工业区很容易在该区域内外的主要道路上造成交通拥堵,因为即使是5车道的道路也不足以处理此类交通。

One of the approaches to this problem is “Sharding”.

其中一个办法解决这个问题的是“ 拆分 ”。

Image for post

Sharding” means dividing large industrial zones into small distributed industrial zones. This would significantly reduce the load on the main roads leading into or leading out of the zones.

拆分 ”是指将大型工业区分成小的分布式工业区。 这将显着减少通往区域的主要道路的负荷。

在软件工程中 (In software engineering)

Image for post

Sharding is used to divide giant data sets into smaller distributed data sets. It’s a popular technique in database optimization.

拆分是用来划分巨大的数据集分成更小的分布式数据集。 这是数据库优化中的流行技术。

组件的专用资源和路由 (Dedicated resources and routings for components)

Let’s revisit the ambulance example. The last thing you would like to is for AMBULANCES to be stuck in traffic with TRUCKS as they are serving different “stakeholders”. Ambulances serve residentials, trucks do not.

让我们回顾一下救护车的例子。 您最后要做的就是让AMBULANCESTRUCKS保持联系,因为它们服务于不同的“利益相关者”。 救护车服务于住宅,卡车则不服务。

It seems to be common sense to mix between residential areas and commercials areas. However, traffic would easily be mixed up between the two.

在住宅区和商业区之间混合似乎是常识。 但是,流量很容易在两者之间混合。

It is more efficient to split residential, commercial, and industrial zones to its own areas. Each of these zones would need dedicated roads leading from highways to them.

将住宅,商业和工业区划分为自己的区域效率更高。 这些区域中的每个区域都需要从高速公路通向它们的专用道路

在软件工程中 (In software engineering)

Similarly in software, it is not desirable for traffic from analytics collectors or asset serving to affect core Web/API servers.

类似地,在软件中,来自分析收集器的流量或资产服务影响核心Web / API服务器也是不希望的。

Therefore, in practices, different domains are used for each of them to maximize browser concurrency since browsers limit concurrency per domain.

因此,在实践中,由于浏览器限制每个域的并发性,因此对每个使用不同的域以最大化浏览器的并发性。

Different sets of servers are also used for each of the purposes. Web/API servers would be separated from Analytics collection servers. Assets would usually utilize CDN to optimize both delivery speed and traffic.

每种目的还可以使用不同组的服务器 。 Web / API服务器将与Analytics收集服务器分开。 资产通常会利用CDN来优化投放速度和流量。

结论 (Conclusion)

Those are just some of the aspects that I find interesting similar between City planning and Software design. What do you think about it? I would like to hear your thoughts.

这些只是我发现城市规划和软件设计之间相似的一些方面。 你怎么看待这件事? 我想听听你的想法。

Thanks for reading!

谢谢阅读!

翻译自: https://medium.com/swlh/cities-skylines-from-a-software-engineers-point-of-view-709d75229b86

城市天际线下载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值