Giter Club home page Giter Club logo

ip-counter's Introduction

ip-counter

Maven

Count unique IPV4 addresses in the provided file according to task

Usage

The app is provided as an executable jar with the main class IpCounter.

Example of usage

mvn package
java -jar target/ip-counter.jar target/test-classes/ips15.in 

Performance

The main task of this implementation is to maximize the utilization of provided resources.

Key improvements

  • Avoid String creation using reading file by byte and composing integer value corresponding to IP.
  • Provide special data structure to store set of int values efficiently. It requires $2^{32}$ bits to store all possible IPs which is around 512Mb of heap memory.
  • Support for concurrent access to the data structure using AtomicIntegerArray
  • Concurrent processing of file: file is split into independent parts and processed in parallel if possible. The approach is implemented using reactive Flow API.
  • Using MappedByteBuffer for faster reading parts of a file.
  • Minimize arithmetic operations during scans (caching appending of read digit (res = res*10 + digit)), replace arithmetic operations with a bit one if possible.

Performance result

Measurements are performed on a low-middle laptop with the following characteristics:

Processor AMD Ryzen 7 3700U with Radeon Vega Mobile Gfx 2.30 GHz
RAM 16.0 GB (14.9 GB usable)
SSD NVMe____WDC_PC_SN530_SDB7
OS Windows 11 (ver. 22H2)
JDK [email protected]

Example of measurements

Handling of provided file with the size of 120GB takes about 2 min in average.

PS C:\Users\unrea> Measure-Command { java -jar C:\Users\unrea\IdeaProjects\ip-counter\target\ip-counter.jar D:\ip_addresses\ip_addresses | Out-Host }
1000000000


Days              : 0
Hours             : 0
Minutes           : 2
Seconds           : 11
Milliseconds      : 99
Ticks             : 1310990407
TotalDays         : 0.00151735000810185
TotalHours        : 0.0364164001944444
TotalMinutes      : 2.18498401166667
TotalSeconds      : 131.0990407
TotalMilliseconds : 131099.0407

ip-counter's People

Contributors

unrealwork 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.