require 'socket'
# step1 create
socket = Socket.new(:INET, :STREAM)
# step2 bind(skip)
# step3 connect
remote_addr = Socket.pack_sockaddr_in(80, 'google.com')
socket.connect(remote_addr)
while data = socket.readpartial(one_hundred_kb) do
puts data
end
# step4 close
socket.close
http://stackoverflow.com/questions/8649860/ruby-tcpsocket-http-request
[book] Working with TCP Sockets
大便时遇到这个问题,顺便回一下。
socket.read
是个 block 的操作,如果 server 没有返回 eof,客户端不会打印出任何东西。
所以应该使用 partial read 来替代 read。
感谢楼主的精彩分享,这篇文章确实极其精彩,我刚好这两天也在反复的读,特此补充,哈哈。
这个地方翻译欠妥。查找常量时 Module.nesting 并不是当前的代码定义的 class。
Ruby 有三种 context
self 当前对象
definee 当前类
lexical scope
作者在此处指的是第三种 context:lexical scope。lexical scope 只和 class 和 module 这两个 keyword 有关。
所以作者最后的结论是两个:
Module.nesting 取决于 lexical scope
lexical scope 只取决于 class、module 两个关键字。(和 class_eval、instance_eval 无关)
原文用的 attach Object,不是 Open Object,此处确实很难翻译。
class C end
在顶级定义一个类 C 时,是把 C 这个常量 attach 到
Object
这个 Rclass 的 constant table 中。
花里胡哨的感觉。
请教一个问题
require 'socket'
local_socket = Socket.new(:INET, :STREAM)
local_addr = Socket.pack_sockaddr_in(4481, '0.0.0.0')
local_socket.bind(local_addr)
server.listen(Socket::SOMAXCONN)
# accept a connection
connection, remote_addr = server.accept
建立连接后,connection 是一个 Socket 对象,instance_variable 是空的,local_address/remote_address 是保存在哪里呢?
> connection.instance_variables
> []
> p connection.local_address
Local address: #<Addrinfo: 0.0.0.0:4481 TCP>
> p connection.remote_address
Remote address #<Addrinfo: 59.102.12.1:4481 TCP>
同问,
为啥不考虑 jruby?
如果用 golang 重写的话,所有的业务逻辑是不是都要重新实现一遍?而且要和 Rails 中的业务逻辑始终保持一致,维护的工作量是不是有点大?
哈哈,我来抢沙发。
这和标题不符啊,哈哈。
shell: $PATH
Ruby: $LOAD_PATH
他们的用途好像啊
果断 redis 的 zset 哇。
请问 mina 到底比 cap 快在哪些地方?
一些比较慢的操作是不可避免的呀。
比如每次部署最耗时间的部分 assets compile 是逃不过去的呀?
这篇文章又系统,又通俗,真是篇好文章。
可以在本机造一亿条假数据,索引之间的差异会拉大。此外 SET SESSION query_cache_type=0;
可以在当前连接的 session 关闭缓存。
Without creating a stored procedure, one technique I've applied is to use the table itself to add the columns. First seed it with a value...
insert into table_name ( column1, column2, column3, column4 )
values ( 1, 2, 3, 4 );
Then insert again, selecting from this table to double the rows each time...
insert into table_name ( column1, column2, column3, uuid)
select round( rand()*10000), 0, 0, UUID() from rand_numbers;
You don't need to run the second query that many times to get quite a few random rows. Not as "neat" as using a stored procedure of course, just proposing an alternative.
client_type 和 status 的值的种类都很少
client_type
status
某个字段的值特异度很低的情况下,建索引比起全表扫描节省不了多少时间。所以我的看法是,这个字段的索引没啥用。
炮哥,你怎么看?
@ hooopo
找个 ruby 工作,跟着大牛一步步学
无所谓,都行
我觉可以从这么几个角度来打分。
if there is no primary key, innodb will create a hidden column as primary key, and cluster rows on it
我喜欢打击人,哈哈。
你收集完了这些资源后,花了多少时间去学习这些课程?
help me...
可能还没有正式 release,你可以在 gemfile 中指定仓库地址和 commit sha,使用 6.0.2
👍
为什么没有人说:用 elasticsearch 呀
感谢 @zgm @serco 以及炮哥的解答。 :plus1:
我以前彻底的混淆了这两种查询的处理流程,他们两个查询时的策略完全不一样的。
query 1
-- ms 级别
-- token 已经加了索引
select count(*) from devices where token="xxx"
query 2
select count(*) from devices
在 Query1 中,mysql 会考虑 devices_token, devices_token_prefix_index 两个索引,最终选择了 selectivity 最高的索引 devices_token。
这个查询是 ms 级别的。
在 query 2 中,MySQL optimizer 会考虑使用以下三个索引:
device_token_prefix_index 体积最小,所以会优先用它。
在 InnoDB 存储引擎中,primary key 是 clustered index(最大的索引),使用它来处理 select count(*) from table_name
最慢。
但这样牵扯出一个新的疑问:
除了 constant table,所有的 select count(*) from table_name
都是一种低效的查询,是这个样子吗?