如何使三项有偿eta服务免费

This is a story on how to not spend even a penny by using three ETA (estimated time of arrival) services instead of one. Everything is based on my personal experience working as a back-end developer at GoDee project. GoDee is a start-up project that offers booking seats on a bus online. You could find more information about this project here:

这是一个关于如何通过使用三个ETA(预计到达时间)服务而不是一个来节省一分钱的故事。 一切都基于我在GoDee项目中担任后端开发人员的个人经验。 GoDee是一个初创项目,可在线预订巴士座位。 您可以在这里找到有关该项目的更多信息:

史前史 (Prehistory)

GoDee is a public transportation service. Bus transportation by GoDee is more convenient than motorbikes common for Southeast Asia and cheaper than a taxi. The app-based system allows users to find an appropriate route, select the time, book the seat, and pay for the ride online. And one of the problems of GoDee is traffic jams that severely impact the user experience. Users get tired of waiting and get annoyed by trying to guess the bus arrival time. So, to make the commuting more convenient, it needed service to calculate the bus’s approximate arrival time, aka ETA.

GoDee是一项公共交通服务。 GoDee的巴士交通比东南亚常见的摩托车更加便捷,而且比出租车便宜。 基于应用程序的系统允许用户找到合适的路线,选择时间,预定座位并在线支付乘车费用。 GoDee的问题之一是交通拥堵,严重影响了用户体验。 用户厌倦了等待,并试图猜测公共汽车的到达时间而感到烦恼。 因此,为了使通勤更加方便,需要服务来计算公共汽车的大概到达时间,也就是ETA。

Developing ETA from scratch would take at least a year. So, to speed up the process, GoDee decided to implement the Google Distance Matrix API tool. Later they developed their own Pifia micro-service.

从头开始开发ETA至少需要一年的时间。 因此,为了加快这一过程,GoDee决定实施Google Distance Matrix API工具。 后来,他们开发了自己的Pifia微服务。

Image for post

问题 (Problems)

Over time, the business grew, and the user base increased. We encountered a problem with increasing requests in the Google Distance Matrix API.

随着时间的流逝,业务不断增长,用户基础也随之增加。 我们在Google Distance Matrix API中遇到了请求增加的问题。

为什么这是个问题? (Why is this a problem?)

Because every request costs money, Google API provides 10.000 free queries per month, after which every 1.000 queries are charged $20. At that time, we had about 150,000 requests per month.

由于每个请求都要花钱,因此Google API每月提供10.000个免费查询,此后每1.000个查询收费20美元。 当时,我们每月大约有150,000个请求。

My mentor was very dissatisfied with that. And said that system should change caching to store ETA every 30 minutes. At that time, the system sent requests to the Google API every 3 seconds to get fresh data. However, such a caching algorithm wasn’t efficient, since minibuses were stuck in traffic. And so the distance only changed once every ten minutes. There was another nuance. For example, five users are asking for information about the same bus, and this is the same request. The cache solved this type of problem.

我的导师对此非常不满意。 并表示系统应每30分钟更改缓存以存储ETA。 那时,系统每3秒向Google API发送一次请求,以获取最新数据。 但是,这样的缓存算法效率不高,因为小巴卡在了交通中。 因此,距离每十分钟仅更改一次。 还有另一个细微差别。 例如,五个用户正在询问有关同一总线的信息,而这是同一请求。 缓存解决了此类问题。

Сache Code
疼痛码

替代服务 (Alternative services)

The cache worked, but not for long since GoDee grew even further and faced the same problem — the number of queries has increased again.

缓存起作用了,但是自从GoDee进一步发展并面临相同的问题之后不久,查询的数量又增加了。

It was decided to replace the Google API with OSRM. Basically, OSRM is a service for building a route based on ETA (this is a rough but the short description, if you need details, here is the link).

决定用OSRM替换Google API。 基本上,OSRM是构建基于ETA的路由服务(这是一个粗略的,但简短的说明,如果你需要的细节,这里是链接 )。

The Open Source Routing Machine or OSRM is a C++ implementation of a high-performance routing engine for the shortest paths in road networks.

开源路由机或OSRM是高性能路由引擎的C ++实现,用于公路网中最短的路径。

Wikipedia.

维基百科。

Mad Devs Software Development Services.

OSRM has one problem: it builds routes and calculates ETA without taking traffic into account. To solve this problem, I started looking for services that can provide information about traffic in the specified part of the city. HERE Traffic was providing the data I needed. After a little study of the documentation, I wrote a small code that gets traffic information every 30 minutes. And to upload traffic information to OSRM, I wrote a small script with the command ./osrm-contract data.osrm --segment-speed-file updates.csv (more details here).

OSRM存在一个问题:它在不考虑流量的情况下构建路由并计算ETA。 为了解决这个问题,我开始寻找可以提供有关城市指定区域交通信息的服务。 HERE Traffic在提供我需要的数据。 在对文档进行了一些研究之后,我编写了一个小代码,每30分钟获取一次交通信息。 为了将路况信息上传到OSRM,我编写了一个小脚本,使用命令./osrm-contract data.osrm --segment-speed-file updates.csv ( 在此处有更多详细信息)。

Math time: every half of the hour, there is a request to HERE to get traffic information this are two requests per hour, that is, a day is 48 requests (24 * 2 = 48) and a month is about ≈ 1.488 (48*31 = 1.488) a year 17.520. Yes, we have these free requests from HERE for 15 years would be enough.

数学时间:每半小时就有一个请求要在此处获取交通信息,这是每小时两个请求,即一天是48个请求(24 * 2 = 48),一个月大约是1.488(48 * 31 = 1.488)每年17.520。 是的,我们收到HERE的这些免费请求15年就足够了。

Code for getting traffic
获取流量的代码

Preliminary tests showed that the service works perfectly, but there is a problem, HERE gives traffic information in “gibberish” and the data does not match the OSRM format. In order for the information to fit, you need to use another service HERE for geocoding + OSRM (for getting points on the map). This is approximately 450.000 requests per month. Later, OSRM was abandoned because the number of requests exceeded the free limit. We didn’t give up and enabled the HERE Distance Matrix API and temporarily removed the Google Distance Matrix API. The logic HERE is simple: we send coordinates from point A to point B and get the bus arrival time.

初步测试表明,该服务可以正常工作,但是存在一个问题,HERE以“乱码”提供了流量信息,并且数据与OSRM格式不匹配。 为了使信息适合您,您需要在此处使用另一项服务进行地理编码+ OSRM(用于在地图上获取点)。 每月大约有450.000个请求。 后来,OSRM被放弃,因为请求数量超过了免费限制。 我们没有放弃并启用HERE Distance Matrix API,而是暂时删除了Google Distance Matrix API。 这里的逻辑很简单:我们将坐标从A点发送到B点,并获得公交车的到达时间。

After we installed everything on the test server and started checking, we received the first feedback from the testers. They said that ETA reads the time incorrectly. We started looking for the problem, looked at logs (we used Data dog for logs), logs, and tests showed that everything works perfectly. We decided to ask about the problem in a little more detail, and it turned out that if the car is in traffic for 15 minutes, ETA shows the same time. We decided that this is because of the cache because it stores the original time and does not update it for 30 minutes.

将所有内容安装在测试服务器上并开始检查之后,我们收到了测试人员的第一条反馈。 他们说,ETA错误地读取了时间。 我们开始寻找问题,查看日志(我们使用Data dog来记录日志),日志和测试表明一切正常。 我们决定更详细地询问问题,结果发现,如果汽车行驶15分钟,ETA会显示相同的时间。 我们认为这是由于缓存的缘故,因为它存储原始时间,并且不会在30分钟内更新它。

We started looking for the problem, at the beginning we checked the data on the web version of the HERE Distance Matrix API (which is called we go here), everything worked fine, we received the same ETA. This problem was also checked on the google map service. There was no problem. The services themselves show this ETA. We explained everything to testers and businesses, and they accepted everything.

我们开始寻找问题,开始时,我们检查了HERE Distance Matrix API的网络版本上的数据(称为“转到此处”),一切正常,我们收到了相同的ETA。 谷歌地图服务也检查了此问题。 没问题 服务本身显示此ETA。 我们向测试人员和企业解释了一切,他们接受了一切。

Our team lead suggested connecting another ETA service and returning the Google API as a backup option and writing code with the logic of switching services (the switch was needed if the requests pass the free number of requests).

我们的团队负责人建议连接另一个ETA服务,并返回Google API作为备份选项,并使用交换服务的逻辑编写代码(如果请求通过免费请求数目,则需要进行交换)。

The code works the following way:

该代码以下列方式工作:

val = getCount() // getting the number of queries usedif getMax() <= val { // checking for the limit of free requests for the service usednewService = switchService(s) // // if the limit is reached, switch the service returnreturn newService(from, to) // giving the logic of the new service 

We found the following Mapbox service, connected it, installed it, and it worked. As a result, our ETA had:

我们找到了以下Mapbox服务,将其连接,安装并正常运行。 结果,我们的预计到达时间为:

“Here” — 250,000 free requests per monthGoogle — 10,000 free requests per monthMapbox — 100,000 free requests per month

“此处”-每月250,000个免费请求Google-每月10,000个免费请求Mapbox-每月100,000个免费请求

结论 (Conclusion)

Always look for alternatives, sometimes it happens that the business doesn't want to pay the money for the service and refuses it. As a developer who has worked hard on the service, you should bring the task to real use. This article describes how we were trying to connect more services for the free use of ETA because the business did not want to pay for the service.

始终寻找替代方案,有时会发生企业不想为服务付费的情况而拒绝了。 作为致力于该服务的开发人员,您应该使该任务真正投入使用。 本文介绍了我们如何尝试连接更多服务以免费使用ETA,因为企业不想为该服务付费。

P.S. As a developer, I believe that if the tool is good and does its job well, then you can pay for the tool’s services (or find Open source projects :D).

PS:作为开发人员,我相信,如果该工具不错,并且能很好地完成工作,那么您可以为该工具的服务付费(或找到开源项目:D)。

Mad Devs Services.

翻译自: https://blog.maddevs.io/how-to-make-three-paid-eta-services-one-free-6edc6affface

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值