Created
March 1, 2013 05:58
-
-
Save pjc0247/5062732 to your computer and use it in GitHub Desktop.
em performance test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'eventmachine' | |
require 'Win32API' | |
$t = Win32API.new("kernel32", "GetTickCount", nil, 'L') | |
$t.call() | |
class Packet | |
attr_accessor :id | |
attr_accessor :size | |
attr_accessor :data | |
attr_accessor :ch | |
def initialize(id = 0, ch = "*") | |
@data = {} | |
@id = id | |
@ch = ch | |
end | |
def dispose | |
end | |
# 패킷에 데이터를 넣는다 | |
def push(name,data) | |
if name == nil | |
return | |
end | |
@data[name] = data | |
end | |
# 패킷에서 데이터를 가져온다 | |
def get(name) | |
if name == nil | |
return | |
end | |
@data[name] | |
end | |
# 패킷에 데이터를 넣는다 | |
def []=(name,data) | |
push(name, data) | |
end | |
# 패킷에서 데이터를 가져온다 | |
def [](name) | |
get(name) | |
end | |
# 패킷을 전송할 채널을 설정한다 | |
def ch=(ch) | |
@ch = ch | |
end | |
# 패킷의 채널 값을 가져온다 | |
def ch | |
@ch | |
end | |
end | |
class Connection < EM::Connection | |
include EM::P::ObjectProtocol | |
def initialize(*args) | |
p = Packet.new | |
#send_object p | |
p.id = 1 | |
100.times do | |
p["ping"] = $t.call() | |
send_object p | |
end | |
end | |
def unbind | |
end | |
def receive_object(obj) | |
#p obj | |
if ($t.call() - obj["ping"]) > 0 | |
puts ($t.call() - obj["ping"]) | |
end | |
end | |
end | |
EM::run do | |
EM::connect "localhost", 9916, Connection | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'eventmachine' | |
class Packet | |
attr_accessor :id | |
attr_accessor :size | |
attr_accessor :data | |
attr_accessor :ch | |
def initialize(id = 0, ch = "*") | |
@data = {} | |
@id = id | |
@ch = ch | |
end | |
def dispose | |
end | |
# 패킷에 데이터를 넣는다 | |
def push(name,data) | |
if name == nil | |
return | |
end | |
@data[name] = data | |
end | |
# 패킷에서 데이터를 가져온다 | |
def get(name) | |
if name == nil | |
return | |
end | |
@data[name] | |
end | |
# 패킷에 데이터를 넣는다 | |
def []=(name,data) | |
push(name, data) | |
end | |
# 패킷에서 데이터를 가져온다 | |
def [](name) | |
get(name) | |
end | |
# 패킷을 전송할 채널을 설정한다 | |
def ch=(ch) | |
@ch = ch | |
end | |
# 패킷의 채널 값을 가져온다 | |
def ch | |
@ch | |
end | |
end | |
class Connection < EM::Connection | |
include EM::P::ObjectProtocol | |
def initialize(*args) | |
p "new connection" | |
end | |
def unbind | |
end | |
def receive_object(obj) | |
send_object obj | |
end | |
end | |
EM::run do | |
EventMachine::start_server "localhost", 9916, Connection | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment