Giter VIP home page Giter VIP logo

grahamking / key-value-polyglot Goto Github PK

View Code? Open in Web Editor NEW
158.0 158.0 32.0 151 KB

A basic key-value store, repeated in C, Go, Python (basic, gevent, and diesel), Ruby (event machine), Java, Scala, Haskell, and NodeJS.

Home Page: http://www.darkcoding.net/software/in-memory-key-value-store-in-c-go-and-python/

Haskell 11.76% C 27.00% Ruby 3.42% Java 11.73% JavaScript 6.74% Scala 10.65% Go 8.29% Python 20.40%

key-value-polyglot's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

key-value-polyglot's Issues

The Java version is incorrect and also doesn't share the same logic as the Python version does

  1. The routine inside handleConnection() accesses the socket input both by a scanner and a raw input stream, which is incorrect since a scanner does buffered reading and makes it impossible to read the value bytes later by a raw input stream.
  2. The Java version uses a PrintWriter with auto flush enabled to write data into the socket, while the Python version manually flushes out at the end of each loop. This difference has huge impact on the benchmark result. You can try to flush out on every write in the Python version to see how slow it could be:
    def output(sockfile, string):
        """Actually write to socket"""
        sockfile.write(string)
        sockfile.flush() #experiment: auto flush on every write

I'll submit a pull request to fix the Java version. It's a version which replicates the logic of the Python version, without any further performance tuning.

I got the benchmark result as below, and the Java version is faster:

#Test against the Python server
#usr and sys times are omitted
#python 2.7.3, Ubuntu 12.04.1 LTS
Key-Value-Polyglot$ for i in {1..5}; do time python test.py; done
real    0m1.684s
real    0m1.660s
real    0m1.670s
real    0m1.666s
real    0m1.676s
#Test against the Java server
#usr and sys times are omitted
#java 1.7.0_07, Ubuntu 12.04.1 LTS
Key-Value-Polyglot$ for i in {1..5}; do time python test.py; done
real    0m2.984s #the first test could be slower as JIT is not warmed up
real    0m1.494s #faster than Python 
real    0m1.460s
real    0m1.395s
real    0m1.368s

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.