Neo4j.rb 3.0版性能降低,所有查询都超过1024毫秒

时间:2014-10-18 09:12:13

标签: ruby-on-rails neo4j neo4j.rb

以下是我正在使用的宝石

gem 'neo4j', github: 'andreasronge/neo4j

以下是模特用户和朋友:

User.rb

class User 


include Neo4j::ActiveNode

  property :name, :type => String, :index => :exact
  property :mood, :type => String
  property :status, :type => String
  property :dob, :type => DateTime, :index => :exact
  property :uid, :type => String, :index => :exact, :unique => true
  property :username, :type => String
  property :email, :type => String, :index => :exact
  property :gender, :type => String, :index => :exact
  property :remember_token, :type => String, :index => :exact
  property :fb_access_token, :type => String, :index => :exact

  scope :gender_filter, ->(g){ where(gender: g)}

  property :friends_list

  serialize :friends_list

  #before_save :create_remember_token

  validates :email, :uniqueness => true

  has_many :both, :friends,  model_class: User,  rel_class: Friend
  has_many :both, :friend_girls,  model_class: User,  rel_class: Friend_girl
  has_many :both, :friend_boys,  model_class: User,  rel_class: Friend_boy
  has_many :both, :places,  model_class: Location,  rel_class: Place


 private
  def create_remember_token
      self.remember_token = SecureRandom.urlsafe_base64
  end

end

Friend.rb

class Friend 
    include Neo4j::ActiveRel
    property :provider, :type => String

  from_class User
  to_class   User
  type 'friends'

end

以下是查询exectution的控制台日志:

 CYPHER 1022ms MATCH (n:`User`) WHERE n.remember_token = {n_remember_token} RETURN n LIMIT 1
 User#friend_boys 1077ms MATCH (user0:`User`), (result:`User`), user0-[rel0:`friend_boys` {_classname: "Friend_boy"}]-(result:`User`) WHERE ID(user0) = 0 RETURN resu
lt LIMIT 8
  Rendered users/_list.html.erb (7425.9ms)
  Rendered users/friends.html.erb within layouts/application (7456.0ms)
  Rendered layouts/_shim.html.erb (1.0ms)
 User#places 1063ms MATCH (user0:`User`), (result:`Location`), user0-[rel0:`places` {_classname: "Place"}]-(result:`Location`) WHERE ID(user0) = 0 RETURN result
  Rendered layouts/_header.html.erb (25855.1ms)
  Rendered layouts/_sidebar.html.erb (3.0ms)
Completed 200 OK in 36067ms (Views: 33981.5ms) 

但在Neo4j管理控制台中,相同的个人查询大约需要350毫秒。

我正在使用neo4j-commnunity edition'2.1.3'

请帮助我提高性能,因为与其他数据库相比这太慢了

更新1:

正如所建议的,我删除了数据目录并重新安装了neo4j-community(2.1.3)但没有任何改变,性能仍然很慢,所以我决定安装新版本neo4j-community(2.1.5)保持现有数据目录就地,再次结果相同。然后我删除了数据目录并再次安装了neo4j-community(2.1.5),这次我的rails应用程序中的一些查询的性能更好,而我的pervious设置中的所有查询都超过了​​1000ms。

以下是日志:

实例1:

 CYPHER 2025ms MATCH (n:`User`) WHERE n.remember_token = {n_remember_token} RETURN n LIMIT 1 | {:n_remember_token=>"dZGEOm0aKxDYkIQ5PfGjnw"}

 CYPHER 16ms MATCH (result:`User`) WHERE result.email = {result_email} AND NOT ID(result) = {record_neo_id} RETURN COUNT(result) AS count | {:record_neo_id=>171, :result_email=>"achal.rvce@gmail.com"}

实例2:

 CYPHER 15ms MATCH (n:`User`) WHERE n.remember_token = {n_remember_token} RETURN n LIMIT 1 | {:n_remember_token=>"dZGEOm0aKxDYkIQ5PfGjnw"}

 User#friend_girls 25ms MATCH (user171:`User`), (result:`User`), user171-[rel0:`friend_girls`]-(result:`User`) WHERE ID(user171) = {ID_user171_} RETURN result LIMIT 8 | {:ID_user171_=>171}

在第1实例:

正如您在第二个查询中所看到的那样,与之前的设置尝试相比,它只需要16毫秒,总是需要超过1000毫秒。

但是对于第一个查询,性能太慢,超过2秒。

在第2实例:

相同的查询耗时超过2秒,现在耗时15毫秒(可能是缓存查询)。但这并不一致,因为连续执行相同的查询,有时需要2秒,有时不到20毫秒。

在第3实例:

 CYPHER 1033ms MATCH (n:`Location`) WHERE n.address = {n_address} RETURN n LIMIT 1 | {:n_address=>"Vijayanagar, Karnataka, India"}

 CYPHER 14ms MATCH (n:`User`) WHERE n.remember_token = {n_remember_token} RETURN n LIMIT 1 | {:n_remember_token=>"dZGEOm0aKxDYkIQ5PfGjnw"}

 CYPHER 90ms START start = node(171), end = node(173) CREATE start-[rel0:`places` {_classname: "Place"}]->end

 CYPHER 16ms MATCH (result:`User`) WHERE result.email = {result_email} AND NOT ID(result) = {record_neo_id} RETURN COUNT(result) AS count | {:record_neo_id=>171, :result_email=>"achal.rvce@gmail.com"}

 User#places 59ms MATCH (user171:`User`), (result:`Location`), user171-[rel0:`places`]-(result:`Location`) WHERE ID(user171) = {ID_user171_} RETURN count(result) AS count | {:ID_user171_=>171}

 User#places 14ms MATCH (user171:`User`), (result:`Location`), user171-[rel0:`places`]-(result:`Location`) WHERE ID(user171) = {ID_user171_} RETURN result | {:ID_user171_=>171}

在实例3中,我们可以注意到只有第一个查询很慢,所有其他查询都很快。

更新2:

以下是bundle update

之后的日志
Started GET "/" for 127.0.0.1 at 2014-10-28 08:14:26 +0530
Processing by StaticPagesController#home as HTML
 CYPHER 1030ms MATCH (n:`User`) WHERE n.remember_token = {n_remember_token} RETURN n LIMIT 1 | {:n_remember_token=>"xqbwLZFzaULDZUKihEql5Q"}
  Rendered users/_default_pic.html.erb (3.0ms)
  Rendered users/_pics_grid.html.erb (4.0ms)
 User#places 5ms MATCH (user184:`User`), (result:`Location`), user184-[rel0:`places`]-(result:`Location`) WHERE ID(user184) = {ID_user184_} RETURN count(result) AS c
ount | {:ID_user184_=>184}
  Rendered users/_places.html.erb (17.0ms)
  Rendered users/_my_badges.html.erb (1.0ms)
  Rendered users/_profile_pics.html.erb (0.0ms)
  Rendered users/_show.html.erb (200.1ms)
  Rendered static_pages/home.html.erb within layouts/application (204.2ms)
  Rendered layouts/_shim.html.erb (0.0ms)
 User#places 0ms MATCH (user184:`User`), (result:`Location`), user184-[rel0:`places`]-(result:`Location`) WHERE ID(user184) = {ID_user184_} RETURN result | {:ID_user
184_=>184}
  Rendered layouts/_header.html.erb (499.6ms)
  Rendered layouts/_sidebar.html.erb (3.0ms)
Completed 200 OK in 2100ms (Views: 1064.7ms)


Started GET "/" for 127.0.0.1 at 2014-10-28 08:14:35 +0530
Processing by StaticPagesController#home as HTML
 CYPHER 2036ms MATCH (n:`User`) WHERE n.remember_token = {n_remember_token} RETURN n LIMIT 1 | {:n_remember_token=>"xqbwLZFzaULDZUKihEql5Q"}
  Rendered users/_default_pic.html.erb (2.0ms)
  Rendered users/_pics_grid.html.erb (0.0ms)
 User#places 5ms MATCH (user184:`User`), (result:`Location`), user184-[rel0:`places`]-(result:`Location`) WHERE ID(user184) = {ID_user184_} RETURN count(result) AS c
ount | {:ID_user184_=>184}
  Rendered users/_places.html.erb (14.0ms)
  Rendered users/_my_badges.html.erb (0.0ms)
  Rendered users/_profile_pics.html.erb (17.9ms)
  Rendered users/_show.html.erb (221.0ms)
  Rendered static_pages/home.html.erb within layouts/application (226.1ms)
  Rendered layouts/_shim.html.erb (0.0ms)
 User#places 5ms MATCH (user184:`User`), (result:`Location`), user184-[rel0:`places`]-(result:`Location`) WHERE ID(user184) = {ID_user184_} RETURN result | {:ID_user
184_=>184}
  Rendered layouts/_header.html.erb (474.4ms)
  Rendered layouts/_sidebar.html.erb (1.0ms)
Completed 200 OK in 3094ms (Views: 1053.2ms)


Started GET "/assets/xeditable/img/loading.gif" for 127.0.0.1 at 2014-10-28 08:15:57 +0530


Started POST "/users/de30de56-7898-4d6b-8be4-c18a0c4915d6/update_status" for 127.0.0.1 at 2014-10-28 08:16:15 +0530
Processing by UsersController#update_status as JSON
  Parameters: {"name"=>"xe_status", "value"=>"i am doing good", "pk"=>"1", "id"=>"de30de56-7898-4d6b-8be4-c18a0c4915d6"}
 CYPHER 1016ms MATCH (n:`User`) WHERE n.remember_token = {n_remember_token} RETURN n LIMIT 1 | {:n_remember_token=>"xqbwLZFzaULDZUKihEql5Q"}
 CYPHER 26ms MATCH (result:`User`) WHERE result.email = {result_email} AND NOT ID(result) = {record_neo_id} RETURN COUNT(result) AS count | {:record_neo_id=>184, :re
sult_email=>"achal.rvce@gmail.com"}
Completed 200 OK in 1305ms (Views: 1.0ms)

的Gemfile

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

gem "will_paginate"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data'

gem 'omniauth-facebook'
gem "geocoder"
gem 'rails4-autocomplete'
gem "font-awesome-rails"
gem 'koala'
gem 'newrelic_rpm'
gem 'jquery-turbolinks'


group :production do
    gem 'rails_12factor'
end

gem 'jquery-ui-rails'

gem "string-urlize"  # for making the title the primary key and work as an URL, see Neo4j.rb id_property

platforms :jruby do
  gem 'neo4j-community', '~> 2.0.0'
end

gem 'sidekiq'
gem 'sinatra', require: false
gem 'slim'

gem 'neo4j'

gem 'cloudinary'

group :development do
  gem 'spring'
  gem 'os'
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'meta_request'
  gem 'debugger'
  gem 'foreman'
end

Ruby version is 2.0.0 and Rails version is 4.0.2

0 个答案:

没有答案