项目作者: sothach

项目描述 :
Efficiently process a sequence of integers to determine the minimal value
高级语言: Scala
项目地址: git://github.com/sothach/minimal.git
创建时间: 2019-11-07T11:24:31Z
项目社区:https://github.com/sothach/minimal

开源协议:

下载


Minimal

Efficiently process a sequence of integers to determine the minimal value

Design

This is not a production-grade solution, but demonstrates the use of streaming to process
a large data set without a corresponding - and deleterious - increase is memory footprint

Configuration

The maximum length of allowed frames (in this case, discerete integer values) while decoding, set in conf/application.conf:

  1. input.frame.size=1000

API

Calculate minimum value

Given a data-set consisting of a set of comma-seperated Long integer values (positive and negative), determine and answer with the lowest value

URL : /api/minimal

Method : POST

Auth required : No

Permissions required : None

Data constraints

Provide comma-separated list of integer values in the domain of java.lang.Long

Data example

  1. -994275329,
  2. 906862559,
  3. -36626088,
  4. 743799515,
  5. -201965995,
  6. -21821772,
  7. 322782558,
  8. -422943259,
  9. -956974090

Success Response

Condition : If data set processed ok

Code : 200 SUCCESS

Content example

  1. -999968087

Error Responses

Condition : If empty data-set provided

Code : 400 BAD REQUEST

Content example : no data provided

Run Service

Start the application locally:

  1. % sbt run

Send data to the api:

  1. % curl http://localhost:9000/api/minimal -H "Content-type: multipart/form-data" -d @test/resources/bigfile.dat

This will respond with the minimum value from the data-set:

  1. -999968087

Metrics

Retrieve JVM metrics

API to retrieve JVM metrics values from running service (@codahale)

URL : /metrics

Method : GET

Auth required : No

Permissions required : None

Data example

  1. {
  2. "version" : "4.0.0",
  3. "gauges" : {
  4. "jvm.attribute.name" : {
  5. "value" : "73662@PDQ17526984"
  6. },
  7. "jvm.attribute.uptime" : {
  8. "value" : 150893
  9. },
  10. "jvm.attribute.vendor" : {
  11. "value" : "Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 25.192-b12 (1.8)"
  12. }
  13. },
  14. "timers" : { }
  15. }

Testing

The provided unit tests verify that integer values in the domain
-1000000000 thru 1000000000 are correctly processed, and invalid values
filtered out of the processing. A data-set of 9999 randomly-generated values
is used, see test/resources/bigfile.dat:

  1. sort --numeric-sort bigfile.dat | head
  2. -999968087
  3. -999800455
  4. -999597000
  5. -999008584
  6. -998948663
  7. -998653326
  8. -998463590
  9. -998305391
  10. -998182735
  11. -999968087
  12. -998018946

Author