Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matsumotory/mruby-fast-remote-check
FastRemoteCheck can perform port listening check at high speed using raw socket
https://github.com/matsumotory/mruby-fast-remote-check
mruby socket tcp
Last synced: about 2 months ago
JSON representation
FastRemoteCheck can perform port listening check at high speed using raw socket
- Host: GitHub
- URL: https://github.com/matsumotory/mruby-fast-remote-check
- Owner: matsumotory
- License: other
- Created: 2017-02-17T02:53:12.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-09T14:14:25.000Z (over 6 years ago)
- Last Synced: 2024-10-18T18:25:46.367Z (3 months ago)
- Topics: mruby, socket, tcp
- Language: C
- Homepage:
- Size: 31.3 KB
- Stars: 5
- Watchers: 5
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mruby-fast-remote-check [![Build Status](https://travis-ci.org/matsumotory/mruby-fast-remote-check.svg?branch=master)](https://travis-ci.org/matsumotory/mruby-fast-remote-check)
FastRemoteCheck can perform port listening check at high speed using raw socket.
## install by mrbgems
- add conf.gem line to `build_config.rb````ruby
MRuby::Build.new do |conf|# ... (snip) ...
conf.gem :mgem => 'mruby-fast-remote-check'
end
```## benchmark
`f.ready? :raw` used RAW socket via my user TCP stack using 3 packets. This is very fast.
`f.ready? :connect` used `connect(2)` and SO_LINGER `close(2)` via Kernel TCP stack using 4 packets.
#### 6379 port listeing
```
> f = FastRemoteCheck.new("127.0.0.1", 54321, "127.0.0.1", 6379, 3)
=> #
> a = Time.now; 100000.times {f.ready? :connect}; (Time.now - a).to_f
=> 3.78796
> a = Time.now; 100000.times {f.ready? :raw}; (Time.now - a).to_f
=> 1.066795
```#### 6380 port not listeing
```
> f = FastRemoteCheck.new("127.0.0.1", 54321, "127.0.0.1", 6380, 3)
=> #
> a = Time.now; 100000.times {f.ready? :connect}; (Time.now - a).to_f
=> 1.037658
> a = Time.now; 100000.times {f.ready? :raw}; (Time.now - a).to_f
=> 0.620506
```## example
### Listeing check
```ruby
> f = FastRemoteCheck.new("127.0.0.1", 54321, "127.0.0.1", 6379, 3)
=> #
> f.open_raw?
=> true
> f.ready?(:raw) # alias f.open_raw?
=> true
> f.connectable?
=> true
> f.ready?(:connect) # alias f.connectable?
=> true
> f = FastRemoteCheck.new("127.0.0.1", 54321, "127.0.0.1", 6378, 3)
=> #
> f.open_raw?
=> false
> f.connectable?
=> false
> f = FastRemoteCheck.new("127.0.0.1", 54321, "1.1.1.1", 6378, 3)
=> #
> f.open_raw?
(mirb):8: sys failed. errno: 11 message: Resource temporarily unavailable mrbgem message: recvfrom failed (RuntimeError)
> f.connectable?
(mirb):9: sys failed. errno: 115 message: Operation now in progress mrbgem message: connect failed (RuntimeError)
>
```### ICMP check
```ruby
> FastRemoteCheck::ICMP.new("8.8.8.8", 3).ping?
=> true
> FastRemoteCheck::ICMP.new("8.8.8.9", 3).ping?
(mirb):4: sys failed. errno: 11 message: Resource temporarily unavailable mrbgem message: recv failed (RuntimeError)
>
```## License
under the MIT License:
- see LICENSE file