将副本集迁移到独立后,我对生成的MongoDB设置有一些奇怪的问题.例如,缺少集合的索引.但尝试reIndex()集合失败也出现此错误消息:
> db.members.reIndex()
{
"errmsg" : "exception: dictionary myapp.members.$channel_id_1 should exist, but we got ENOENT",
"code" : 16988,
"ok" : 0
}
Run Code Online (Sandbox Code Playgroud)
问题是如何重新索引错过其索引的集合:)
非常感谢,克里斯
在Rails 2.3中我总是使用
render :json => { :success => true, :data => @foobar}
Run Code Online (Sandbox Code Playgroud)
将JSON数据发送到我的前端.在Rails 3我正在使用
respond_to :json
...
respond_with @foobar
Run Code Online (Sandbox Code Playgroud)
但我缺少的是:我需要JSON结构中的"成功"值.在Rails 3中将这些数据注入JSON响应的正确方法是什么?
嗯,尝试过这个,但是我得到以下错误:
SyntaxError (app/controllers/properties_controller.rb:13: syntax error, unexpected tASSOC, expecting '}'
respond_with { :success => true, :data => @property }
^
/app/controllers/properties_controller.rb:13: Can't assign to true
respond_with { :success => true, :data => @property }
^
app/controllers/properties_controller.rb:13: syntax error, unexpected tASSOC, expecting tCOLON2 or '[' or '.'
respond_with { :success => true, :data => @property }
Run Code Online (Sandbox Code Playgroud) 我正在玩Ruby EventMachines已有一段时间了,我想我理解它的基础知识.
但是,我不确定如何在大文件(120 MB)中进行性能读取.我的目标是逐行读取文件并将每一行写入Cassandra数据库(同样应该使用MySQL,PostgreSQL,MongoDB等,因为Cassandra客户端显式支持EM).简单的片段阻挡了反应堆,对吗?
require 'rubygems'
require 'cassandra'
require 'thrift_client/event_machine'
EM.run do
Fiber.new do
rm = Cassandra.new('RankMetrics', "127.0.0.1:9160", :transport => Thrift::EventMachineTransport, :transport_wrapper => nil)
rm.clear_keyspace!
begin
file = File.new("us_100000.txt", "r")
while (line = file.gets)
rm.insert(:Domains, "#{line.downcase}", {'domain' => "#{line}"})
end
file.close
rescue => err
puts "Exception: #{err}"
err
end
EM.stop
end.resume
end
Run Code Online (Sandbox Code Playgroud)
但是什么是异步读取文件的正确方法?
我写了一个导出器,它在指标旁边公开时间戳,例如:
test_load_min{app="web01"} 1 1483228810000
test_load_min{app="db01"} 2 1483228820000
test_load_min{app="email01"} 3 1483228830000
Run Code Online (Sandbox Code Playgroud)
根据https://prometheus.io/docs/instrumenting/exposition_formats/这对 Prometheus 应该没问题,但在 Prometheus UI 中查询 test_load_min 返回空结果。同样没有时间戳也能正常工作。有人知道那里有什么问题吗?
由于一些限制,我想将我当前的项目从EventMachine/EM-Synchrony切换到Celluloid,但是我很难与它联系.我正在编写的项目是一个网络收集器,它应该尽可能快地抓取大量页面.
为了对Celluloid的基本了解,我在本地Web服务器上生成了10.000个虚拟页面,并希望通过这个简单的Celluloid片段抓取它们:
#!/usr/bin/env jruby --1.9
require 'celluloid'
require 'open-uri'
IDS = 1..9999
BASE_URL = "http://192.168.0.20/files"
class Crawler
include Celluloid
def read(id)
url = "#{BASE_URL}/#{id}"
puts "URL: " + url
open(url) { |x| x.read }
end
end
pool = Crawler.pool(size: 100)
IDS.to_a.map do |id|
pool.future(:read, id)
end
Run Code Online (Sandbox Code Playgroud)
据我了解赛璐珞,期货是获取被激活请求响应的方式(与EventMachine中的回调相当),对吧?另一件事是,每个actor都在自己的线程中运行,所以我需要某种批处理请求,因为10.000线程会导致我的OSX开发机器出错.
所以创建一个游泳池是可行的,对吧?但是:上面的代码迭代了9999个URL,但只有1300个HTTP请求被发送到Web服务器.因此限制请求和迭代所有URL都会出错.
我对这种情况感到困惑,并试图解决这个问题几天了.我在三个3成员副本集(rs0,rs1和rs2)之上运行了3个碎片.到目前为止一切正常.数据分布在3个分片上,并克隆在副本集中.
但是:将数据导入到其中一个副本集中可以正常使用40k docs/s但是通过启用分片可以将整个过程减慢到仅1.5k docs/s.
我通过不同的方法填充数据:
所有这些都只有1.5k doc/s,令人失望.mongod是物理Xeon盒子,每个32GB,3个配置服务器是虚拟服务器(40 GB HDD,2 GB RAM,如果这很重要),mongos在我的app服务器上运行.顺便说一下,1.5k insert/s的值不依赖于分片键,专用分片键(单字段键和复合键)的相同行为以及_id字段上的散列分片键.
我尝试了很多,甚至重新安装了整个集群两次.问题是:此设置的瓶颈是什么:
我的计划是使用部署令牌来访问私有存储库(托管 GitLab)。
这个工作正常:
git clone https://my-gitlab-deploy-token-user:my-gitlab-deploy-token-pass@gitlab.com/username/projectname.git
Run Code Online (Sandbox Code Playgroud)
访问 archive.tgz 失败并显示身份验证错误:
curl https://my-gitlab-deploy-token-user:my-gitlab-deploy-token-pass@gitlab.com/username/projectname/repository/archive.tar.gz?ref=master
Run Code Online (Sandbox Code Playgroud)
任何人都知道为什么令牌身份验证使用 Git 客户端的 HTTP 端点可以正常工作,但无法直接获取存档 tarball?
我正在玩EventMachine已有几天了,它有一个陡峭的学习曲线恕我直言;-)我尝试通过触发HttpHeaderCrawler.query()在回调中返回一个哈希.但是我在这种情况下得到的不是hash {'http_status'=> xxx,'http_version'=> xxx},而是一个EventMachine :: HttpClient对象本身.
我想保持EM.run块干净,并想在自己的类/模块中做所有逻辑,那么如何将这样的值返回到主循环中以通过回调访问它?提前谢谢了 ;-)
#!/usr/bin/env ruby
require 'eventmachine'
require 'em-http-request'
class HttpHeaderCrawler
include EM::Deferrable
def query(uri)
http = EM::HttpRequest.new(uri).get
http.callback do
http_header = {
"http_status" => http.response_header.http_status,
"http_version" => http.response_header.http_version
}
puts "Returns to EM main loop: #{http_header}"
succeed(http_header)
end
end
end
EM.run do
domains = ['http://www.google.com', 'http://www.facebook.com', 'http://www.twitter.com']
domains.each do |domain|
hdr = HttpHeaderCrawler.new.query(domain)
hdr.callback do |header|
puts "Received from HttpHeaderCrawler: #{header}"
end
end
end
Run Code Online (Sandbox Code Playgroud)
此代码段产生以下输出:
Returns to EM main loop: {"http_status"=>302, "http_version"=>"1.1"}
Received from …Run Code Online (Sandbox Code Playgroud) 我怎样才能合并这 2 个 Elixir 地图:
foo = %{a: 1, b: 2, c: [%{d: 3, e: 4}, %{d: 5, e: 6}]}
bar = %{a: 1, b: 2, c: [%{d: 7, e: 8}, %{d: 9, e: 0}]}
Run Code Online (Sandbox Code Playgroud)
...得到以下结果:
%{a: 1, b: 2, c: [%{d: 3, e: 4}, %{d: 5, e: 6}, %{d: 7, e: 8}, %{d: 9, e: 0}]}
Run Code Online (Sandbox Code Playgroud)
SimpleMap.merge(foo,bar)不会这样做,因为 c 的值是一个列表。
先感谢您!克里斯托夫
我切换到Mongoid 3,这使得一些不同的东西:)目前我尝试检查复合字段是否是唯一的:
class Host
include Mongoid::Document
field :ip, :type => String
field :port, :type => Integer
field :username, :type => String
field :password, :type => String
validates_presence_of :ip
validates_presence_of :port
end
Run Code Online (Sandbox Code Playgroud)
如何在其中获取validates_uniqueness_of,检查ip和port是否是唯一的复合字段?AFAIK在Mongoid 2中有一种方法可以基于多个字段创建一个新的_id,但似乎在Mongoid 3中删除了它:
key :ip, :port
Run Code Online (Sandbox Code Playgroud) ruby ×3
eventmachine ×2
mongodb ×2
asynchronous ×1
callback ×1
cassandra ×1
celluloid ×1
composite ×1
concurrency ×1
elixir ×1
file ×1
gitlab ×1
http ×1
indexing ×1
json ×1
maps ×1
mongoid ×1
performance ×1
private ×1
prometheus ×1
replicaset ×1
replication ×1
sharding ×1
timestamp ×1