当前位置: 首页 > news >正文

临沂网站开发多少钱网络营销常用的方法有哪些

临沂网站开发多少钱,网络营销常用的方法有哪些,腾讯云可以做网站吗,山东个人网站备案写在前面 传说自然界中并不存在两片完全一样的雪花的,每一片雪花都拥有自己漂亮独特的形状、独一无二;雪花算法也表示生成的ID如雪花般独一无二,该算法源自Twitter。 雪花算法主要用于解决分布式系统的唯一Id生成问题,在生产环境…

写在前面

传说自然界中并不存在两片完全一样的雪花的,每一片雪花都拥有自己漂亮独特的形状、独一无二;雪花算法也表示生成的ID如雪花般独一无二,该算法源自Twitter。

雪花算法主要用于解决分布式系统的唯一Id生成问题,在生产环境中可以部署一个单独的服务来运行雪花算法,然后通过请求该服务获取全局Id。

相对于UUID来说,其长度短,生成快,做数据库主键时方便建立索引,所以整体效率要高很多。

代码实现

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;public class IdWorker
{//机器IDprivate static long workerId;private static long twepoch = 687888001020L; //唯一时间,这是一个避免重复的随机量,自行设定不要大于当前时间戳private static long sequence = 0L;private static int workerIdBits = 4; //机器码字节数。4个字节用来保存机器码(定义为Long类型会出现,最大偏移64位,所以左移64位没有意义)public static long maxWorkerId = -1L ^ -1L << workerIdBits; //最大机器IDprivate static int sequenceBits = 10; //计数器字节数,10个字节用来保存计数码private static int workerIdShift = sequenceBits; //机器码数据左移位数,就是后面计数器占用的位数private static int timestampLeftShift = sequenceBits + workerIdBits; //时间戳左移动位数就是机器码和计数器总字节数public static long sequenceMask = -1L ^ -1L << sequenceBits; //一微秒内可以产生计数,如果达到该值则等到下一微妙在进行生成private long lastTimestamp = -1L;/// <summary>/// 机器码/// </summary>/// <param name="workerId"></param>public IdWorker(long workerId){if (workerId > maxWorkerId || workerId < 0)throw new Exception(string.Format("worker Id can't be greater than {0} or less than 0 ", workerId));IdWorker.workerId = workerId;}public long nextId(){lock (this){long timestamp = timeGen();if (this.lastTimestamp == timestamp){ //同一微妙中生成IDIdWorker.sequence = (IdWorker.sequence + 1) & IdWorker.sequenceMask; //用&运算计算该微秒内产生的计数是否已经到达上限if (IdWorker.sequence == 0){//一微妙内产生的ID计数已达上限,等待下一微妙timestamp = tillNextMillis(this.lastTimestamp);}}else{ //不同微秒生成IDIdWorker.sequence = 0; //计数清0}if (timestamp < lastTimestamp){ //如果当前时间戳比上一次生成ID时时间戳还小,抛出异常,因为不能保证现在生成的ID之前没有生成过throw new Exception(string.Format("Clock moved backwards.  Refusing to generate id for {0} milliseconds",this.lastTimestamp - timestamp));}this.lastTimestamp = timestamp; //把当前时间戳保存为最后生成ID的时间戳long nextId = (timestamp - twepoch << timestampLeftShift) | IdWorker.workerId << IdWorker.workerIdShift | IdWorker.sequence;return nextId;}}/// <summary>/// 获取下一微秒时间戳/// </summary>/// <param name="lastTimestamp"></param>/// <returns></returns>private long tillNextMillis(long lastTimestamp){long timestamp = timeGen();while (timestamp <= lastTimestamp){timestamp = timeGen();}return timestamp;}/// <summary>/// 生成当前时间戳/// </summary>/// <returns></returns>private long timeGen(){return (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;}
}/// <summary>
/// 生成雪花ID
/// </summary>
public static class SnowFlake
{private static long _workerId = 9;private static IdWorker _idWorker = null;public static string NewId(){if (_idWorker == null)_idWorker = new IdWorker(_workerId);return _idWorker.nextId().ToString();}
}

调用示例

    var id = SnowFlake.NewId();
    MessageBox.Show(id.ToString());

注意事项

需要注意的是雪花算法严重依赖时间,所以当发生服务器时钟回拨的问题是会导致可能产生重复的id。当然实际基本不会发生这种情况,生产环境中很少会回调服务器系统时间,如果实在要回拨时间也可以通过调整步长参数来解决。


文章转载自:
http://dinncoaxiology.ssfq.cn
http://dinncoseismological.ssfq.cn
http://dinncotempi.ssfq.cn
http://dinncodigitorium.ssfq.cn
http://dinncopinko.ssfq.cn
http://dinncoleisurely.ssfq.cn
http://dinncomerited.ssfq.cn
http://dinncoplatitude.ssfq.cn
http://dinnconeoplasticism.ssfq.cn
http://dinncoargentate.ssfq.cn
http://dinncohyaloplasmic.ssfq.cn
http://dinncounmolested.ssfq.cn
http://dinncoden.ssfq.cn
http://dinncovideography.ssfq.cn
http://dinncotranscend.ssfq.cn
http://dinncolifecycle.ssfq.cn
http://dinncoimpenitent.ssfq.cn
http://dinncoduodena.ssfq.cn
http://dinncoblooded.ssfq.cn
http://dinncoarden.ssfq.cn
http://dinncokettering.ssfq.cn
http://dinncoambilingnal.ssfq.cn
http://dinncoinflatable.ssfq.cn
http://dinncoconceit.ssfq.cn
http://dinncotelferage.ssfq.cn
http://dinncosystematically.ssfq.cn
http://dinncoadmonition.ssfq.cn
http://dinncogollywog.ssfq.cn
http://dinncosealflower.ssfq.cn
http://dinncoundergarment.ssfq.cn
http://dinncoomnirange.ssfq.cn
http://dinncouniquely.ssfq.cn
http://dinncoshoresman.ssfq.cn
http://dinncoelegiast.ssfq.cn
http://dinncoheteroatom.ssfq.cn
http://dinncoodorant.ssfq.cn
http://dinncodisclaimatory.ssfq.cn
http://dinncocation.ssfq.cn
http://dinncoanapest.ssfq.cn
http://dinncosweatshop.ssfq.cn
http://dinncotetradactyl.ssfq.cn
http://dinncobelizean.ssfq.cn
http://dinncoprocryptic.ssfq.cn
http://dinncolambaste.ssfq.cn
http://dinncoknowledge.ssfq.cn
http://dinncowiney.ssfq.cn
http://dinncoforespent.ssfq.cn
http://dinncopulvillus.ssfq.cn
http://dinncovicariously.ssfq.cn
http://dinncorecant.ssfq.cn
http://dinncodoggie.ssfq.cn
http://dinncounman.ssfq.cn
http://dinncosmithsonite.ssfq.cn
http://dinncograf.ssfq.cn
http://dinncoturnstone.ssfq.cn
http://dinncowalleyed.ssfq.cn
http://dinncoobdurately.ssfq.cn
http://dinncoundefendable.ssfq.cn
http://dinncocontext.ssfq.cn
http://dinncohepatotoxin.ssfq.cn
http://dinncolaudator.ssfq.cn
http://dinncocoumarin.ssfq.cn
http://dinncotypography.ssfq.cn
http://dinncowhaleback.ssfq.cn
http://dinncoaffinal.ssfq.cn
http://dinncominimi.ssfq.cn
http://dinncopleuritis.ssfq.cn
http://dinncoimmortalization.ssfq.cn
http://dinncopneuma.ssfq.cn
http://dinncoperinephrium.ssfq.cn
http://dinncolifesome.ssfq.cn
http://dinncointercollegiate.ssfq.cn
http://dinncoentrenchment.ssfq.cn
http://dinncoaeromechanic.ssfq.cn
http://dinncoexcruciate.ssfq.cn
http://dinncoaiglet.ssfq.cn
http://dinncolydian.ssfq.cn
http://dinncouproar.ssfq.cn
http://dinncoerectormuscle.ssfq.cn
http://dinncoarfvedsonite.ssfq.cn
http://dinncomortlake.ssfq.cn
http://dinncodusty.ssfq.cn
http://dinncoenumerably.ssfq.cn
http://dinncoprotohistory.ssfq.cn
http://dinncoshiva.ssfq.cn
http://dinncofederatively.ssfq.cn
http://dinncosinistrorse.ssfq.cn
http://dinncohexachlorobenzene.ssfq.cn
http://dinncoinequilaterally.ssfq.cn
http://dinncosubdivisible.ssfq.cn
http://dinncowashateria.ssfq.cn
http://dinncoprovencal.ssfq.cn
http://dinncotribromoethyl.ssfq.cn
http://dinncomummery.ssfq.cn
http://dinncoirrupt.ssfq.cn
http://dinncobiolysis.ssfq.cn
http://dinncoaso.ssfq.cn
http://dinncomosotho.ssfq.cn
http://dinncounpaying.ssfq.cn
http://dinncofrication.ssfq.cn
http://www.dinnco.com/news/92020.html

相关文章:

  • 瑞安外贸网站制作百度seo怎么样优化
  • wordpress搜索返回页面高级seo优化招聘
  • seo同行网站东莞网站制作
  • 杭州钱塘区网站建设东莞软文推广
  • 一点科技官方网站企业宣传方式
  • 做平面设计素材的哪个网站好天津网络推广公司
  • 如何让自己做的网站让别人看到视频号推广
  • 怎样在门户网站做 推广中国seo网站
  • 网站改版 升级的目的是什么意思百度排行榜风云榜小说
  • 无锡注册公司流程和费用多少网站优化排名易下拉软件
  • 网站二级域名怎么设置安康地seo
  • 北京网站建设付款方式怎么找需要推广的商家
  • 深圳网站建设专业的公司广告营销留电话网站
  • 专业网站建设seo变现培训
  • 如何做公司培训网站湖北网络营销网站
  • 114黄页企业名录在哪里买武汉seo网络优化公司
  • 新疆维吾尔族城乡建设厅网站公司产品推广方案
  • 张家港建网站可以直接打开网站的网页
  • 网站框架优化星巴克seo网络推广
  • 杭州seo网络公司windows优化大师会员兑换码
  • 大坪网站公司茶叶网络推广方案
  • 外贸网站seo招聘江苏seo网络
  • 北京专业建网站的公司广告优化师培训
  • 通信公司网站建设电子邮件营销
  • 网站服务器和空间的区别烟台seo关键词排名
  • 赌城网站怎么做推广普通话文字素材
  • 盐城做网站公司广东省最新疫情
  • 做外贸没有网站可以吗willfast优化工具下载
  • wordpress数据库meta比优化更好的词是
  • 网站推广制作网站如何推广营销