Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage#write is very slow #43

Open
qqshfox opened this issue Feb 25, 2013 · 1 comment
Open

Storage#write is very slow #43

qqshfox opened this issue Feb 25, 2013 · 1 comment

Comments

@qqshfox
Copy link

qqshfox commented Feb 25, 2013

This line took 200 ms on my mbp :(

FileUtils.mkdir_p dir_path

Or we could use the tempfile like this? Just a POC.

require 'tempfile'

module MetaRequest
  class Storage
    attr_reader :key

    def initialize(key)
      @key = key
    end

    def write(value)
      tempfiles[json_file].write(value)
    end

    def read
      if tempfiles.has_key?(json_file)
        tempfile = tempfiles[json_file]
        tempfile.rewind
        tempfile.read
      end
    end

    private

    def tempfiles
      @@tempfiles ||= Hash.new { |hash, key| hash[key] = Tempfile.new(key) }
    end

    def json_file
      "#{key}.json"
    end
  end
end

No file pool implemented. Depend on the system how to gc.

The run time reduce to 1.5 ms.

@fifiteen82726
Copy link

I found out it will make a little bit slow in developing. Is this possible to turn off via environment variable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants