如何让服务器实时计算更加高效

发布于 2024-08-16 09:43:33 字数 295 浏览 2 评论 0原文

我在网站上使用 mySQL 数据库根据邮政编码、纬度和经度计算多个点的距离。 例如,邮政编码 123456 处的 A 点的纬度为 100,经度为 200 使用静态公式,计算并实时返回 A 点与其他多个点之间的距离。参考点 A 可能会更改为具有不同纬度/经度的点 B。

问题是服务器 CPU 已达到极限并需要相当长的时间来执行这些计算。我可以增加 CPU 功率,但想知道是否有更有效的方法来做到这一点。

将距离放入数据库中是不切实际的,因为这意味着 N x N 查找 (999999 x 999999),并且随着添加更多数据点,距离将呈指数增长。

I am using a mySQL database on a site to calculate the distance of multiple points based on zipcodes, latitudes and longitudes.
E.g. Point A at zip code 123456 has latitude 100 and longitude 200
Using a static formula, the distance between Point A and multiple other points are calculated and returned real time. The reference Point A may change to Point B with a different lat/long

The issue is that the server CPU is maxing out and taking quite a long time to do these calculations. I can increase CPU power, but wanted to know if there is more efficient way of doing this.

Putting the distances into a DB is not practical as it means a N x N lookup (999999 x 999999) and will increase exponentially as more datapoints are added.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦在夏天 2024-08-23 09:43:33

听起来您正在做类似地理的事情,您是否考虑过 http://postgis.refractions.net/ ? (如果你没有绑定MySQL)因为它是为计算而调整/设计的,有点类似。

As it sounds like you are doing geographic like things, have you considered http://postgis.refractions.net/ ? (if you are not bound to MySQL) as it is tuned/designed for calculations a bit like that.

你没皮卡萌 2024-08-23 09:43:33

数据库服务器的设计并不是以快速算术为主要目标。

确保您充分有效地利用索引。

如果您需要实际值,请使用快速平方根公式距离,否则只需比较距离的平方。

在适当的地方使用缓存。

A database server is not designed with fast arithmetic as a primary goal.

Make sure you are fully utilising indexes efficiently.

Use a fast square root formula if you need actual distances, otherwise just compare the squares of distances.

Use caching wherever it's appropriate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文