GithubHelp home page GithubHelp logo

tinyurl's Introduction

TinyUrl

一个Golang开发的短网址服务

部署方法

Windows下请直接正确配置config.json文件,并且开启好相关环境(MySQL,Redis)然后即可运行bin目录下已经编译好的二进制可执行文件。

Linux下请手动编译,启动时需要开启的环境和Windows一致。

使用方法

可选启动参数:tinyurl.exe -config C:\config.json

首次启动时保证可执行文件目录下有tinyurl.sql.tpl文件,该文件为数据库DDL模版,用于生成数据库表结构。

启动之后访问http://ip:port/l=长网址,会返回json格式的数据,里面有对应的短网址部分,直接访问http://ip:port/短网址即会自动跳转到对应的原始长网址。其中ip,port,l等参数均可在config.json配置文件中修改。


更新日志

Ver 1.0.1 (2017-05-16)

  • 修复缓存读取时所使用的key未加prefix导致所有请求无法利用缓存的缺陷
  • db包下的mysql操作库修正命名为mysql.go
  • 增加rand种子以当前时间戳取值
  • 修复url随机构造部分未考虑到高并发场景下由于rand种子取值窗口过小导致碰撞几率变大,在mysql数据库下当事务隔离级别为“Repeatable read”时可能导致幻读的缺陷

TinyUrl短网址服务(http://github.com/cw1997/TinyUrl)

技术栈:Golang,MySQL,Redis

开发时间:2017.5

开发规模,1人,5天

项目简介:

一个很简单的短网址服务,支持自定义短链接规则,后台使用Golang+缓存+连接池,保功能简单的同时兼顾性能。

项目优点:

  1. 轻量,简单。支持自定义短网址规则。
  2. 通过MySQL持久化存储短网址与长网址的映射。通过Redis缓存加速,通过连接池提升高并发下的IO。
  3. 可控性强,配置化,很多参数可以通过配置文件修改。

项目缺点:

  1. 核心功能未写接口,导致后期替换模块不方便,比如说要把缓存从Redis换成Memcached则需要修改缓存代码。
  2. 短网址生成的算法和策略过于简单,没有解决单个长网址被多次重复提交短网址生成请求时导致的冗余数据问题。
  3. Redis未使用集群,MySQL未使用分库分表,导致后续数据量大的时候可能出现性能以及扩展问题。

项目总结:

虽然Golang是一门开发效率极高的静态强类型编程语言,但是并不意味着用它开发就可以对性能问题高枕无忧了。因为很多应用的性能瓶颈其实都在IO上。使用它开发高并发项目仍然需要对架构与设计有着更多广度和深度的理解。并且由于它本身不是面向对象编程语言,那么写出优雅,高内聚低耦合的项目并不是那么容易。

tinyurl's People

Contributors

cw1997 avatar

Stargazers

 avatar  avatar 5l1v3r1 avatar fdvoid0 avatar  avatar zlchen avatar DongjunZou avatar Su avatar 长弓词 avatar  avatar john avatar  avatar 911 avatar feiandxs avatar 柚子吧 avatar  avatar firstfu avatar Panda avatar 施展 avatar  avatar

Watchers

 avatar

Forkers

woohaha

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.