Giter Club home page Giter Club logo

findtopkurls's Introduction

描述

100GB URL文件,使用1GB内存计算出出现次数TOP 100的URL和出现次数

思路

100GB数据无法一次加载进入内存中,可采用分治法,顺序读文件,使用URL的hash值后根据余数划分到不同的文件中;如果其中的文件超过了限制大小的继续划分直到所有的文件都小于限定大小;对于每个小文件,使用HashMap统计URL的出现频率,然后使用统计结果建立小顶堆;最后将所有的小顶堆合并后得到一个最终小顶堆;

优化思路

分割成为小文件后,每个文件的小顶堆使用线程池的方式进行计算,线程数量不宜过多一般和CPU核心数差不多

运行

执行mvn install编译生成可执行jar,存放在target目录下

进入target目录执行java -jar topk-1.0.0-jar-with-dependencies.jar -g p "./data/" -s 100 生成100G测试数据

然后执行java -jar -Xms512m -Xmx1024m topk-1.0.0-jar-with-dependencies.jar -f "./data/input.txt" -k 100 获取Top100数据

输出结果在同级目录的result.txt

findtopkurls's People

Contributors

gloriawish avatar

Stargazers

 avatar

Watchers

 avatar

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.