如何网址缩短保证唯一的URL时,他们不会过期? [关闭](How do URL shortene

2019-07-30 05:48发布

There are a lot of questions here on stackoverflow regarding URL shorteners as well as elsewhere on the internet, e.g.

How to code a URL shortener?

How do URL shortener calculate the URL key? How do they work?

http://www.codinghorror.com/blog/2007/08/url-shortening-hashes-in-practice.html

However, there is one thing I don't understand. For instance, http://goo.gl uses four characters at the moment. However, they claim their short URLs don't expire. As mentioned in the article on coding horror, if they can't recycle URLs, the only possible solution is at one point to add an additional character.

Ok, so far so good. With 4 characters that means about 15 million unique addresses. For something like Google Maps, I don't think that is very much and if you can't recycle, my guess is they run out of available addresses fairly quickly.

Now for the part I don't get. While handing out addresses, they start to run out of unused addresses. They have to check if a newly generated address has not been issued yet. The chance this has happened and the address is already in use increases. The straightforward solution of course is to generate a new URL over and over again until they find a free one or until they have generated all 1.5 million alternatives. However, this surely can't be how they actually do it, because this would be far too time-consuming. So how do they manage this?

Also, there are probably several visitors at once asking for a short URL, so they must have some synchronization going on as well. But how should the situation be managed when the fifth character needs to be added?

Finally, when doing some research on how the URLs from http://goo.gl work, of course I requested a short URL for a map on Google Maps several times. None of them will ever be used. However, when Google would strictly enforce the policy of URLs not expiring once issued, this means that there are lots and lots of dormant URLs in the system. Again, I assume Google (and the other services as well) have come up with a solution to this problem as well. I could imagine a clean up service which recycle URLs which have not been visited in the first 48 hours after creation or less then 10 times in the first week. I hope someone can shed some light on this issue as well.

In short, I get the general principle of URL shorteners, but I see several problems when these URLs cannot expire. Does anyone know how the problems mentioned above might be resolved and are there any other problems?


EDIT

Ok, so this blog post sheds some light on things. These services don't randomly generate anything. They rely on the underlying database's auto-increment functionality and apply a simple conversion on the resulting id. That eliminates the need to check if an id already exists (it doesn't) and the database handles synchronization. That still leaves one of my three questions unanswered. How do these services "know" if a link is actually used once created?

Answer 1:

为什么URL缩短服务不删除条目

我的确写了TinyURL的(十年前),以回馈我并不需要一个条目。 他们的回答让我意识到我是多么荒谬的是:他们告诉我,“ 只是创建你所需要的所有URL”。 而数字说话本身:

A -随着26低的情况下+ 26个大写字母+ 10个数字(合理位点的选择),使用一个字符给你62点的位置(即,62缩短的URL),然后增加炭由62 乘以位置编号:

  • 0炭= 1网址
  • 1焦炭= 62网址
  • 2个字符= 3844(1个URL用于在每个村庄人)
  • 3个字符= 238328(同上,在一个城市)
  • 4个字符= 14776336(在洛杉矶地区)
  • 5个字符= 916132832(美洲,N +中部+ S)
  • 6个字节〜56800235580(8个网址为每个人在世界上)
  • 7个字符〜3,521,614,606,000(503对于每个人,4为每个网页在世界)
  • 8个字符〜218,340,105,600,000(31191页的URL为每个人)
  • 9个字符〜13,537,708,655,000,000(约2页百万的URL为每个人)
  • 10个字符〜839,299,365,900,000,000(〜120十亿为每个人的URL)的
  • 11个字符〜52,036,560,680,000,000,000

乙 - 实际上的需求和用途是比人们可以预计的要低。 几个人正在创建短网址,而且每个人创建几个URL。 原始网址是足够在大多数情况下。 结果是最流行的缩短器,经过多年,仍然满足需要今天只有4个或5个字符,并在需要的费用几乎为零时加入另一个。 显然的goo.gl和goo.gl/maps分别使用5个字符,YouTube是使用11(使用上述的62个字符,再加上仪表板和其它也许几个)。

Ç - 托管的费用(存储+操作)的URL是,比如说,$ 1000 /年1Terabyte,每TB能容纳5周亿的网址,因此1个URL的托管费用0.2微元/年。 然而,对于Shortener会让效益也非常薄,那里的生意不是很强烈。 对于用户来说,一个URL的好处是难以评估,但错过的链接将花费远远超过了托管。

d - 是毫无意义的,为用户创建一个简短的网址,如果它的风险,成为未来几年不工作,因此持续性是一个Shortener会让一个主要的吸引力,除非他们被迫严重Shortener会让可能永远不会停止为他们服务歇业; 然而这事已了,反正短网址有其缺点的负载以及好处,以及解释维基百科“网址缩短”各种黑客攻击,对用户或靶位点,或Shortener会让的(风险;例如,一个可以通过URL的僵尸请求千兆号攻击Shortener会让,威胁肯定避开了大多数缩短服务)。

凡尔赛星期二2013年3月12日下午8点48分00秒0100,编辑下午9时01分25秒



文章来源: How do URL shorteners guarantee unique URLs when they don't expire? [closed]