Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
814a1fa8
Commit
814a1fa8
authored
Sep 11, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
a8e61d2f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
38 deletions
+94
-38
go/neo/connection.go
go/neo/connection.go
+19
-14
go/neo/t/.gitignore
go/neo/t/.gitignore
+1
-0
go/neo/t/t.sh
go/neo/t/t.sh
+1
-1
go/neo/t/zsha1.go
go/neo/t/zsha1.go
+22
-5
go/neo/t/zsha1.py
go/neo/t/zsha1.py
+51
-18
No files found.
go/neo/connection.go
View file @
814a1fa8
...
...
@@ -65,8 +65,8 @@ type NodeLink struct {
serveWg
sync
.
WaitGroup
// for serve{Send,Recv}
acceptq
chan
*
Conn
// queue of incoming connections for Accept
txq
chan
txReq
// tx requests from Conns go via here
// (rx packets are routed to Conn.rxq)
//
txq chan txReq // tx requests from Conns go via here
//
// (rx packets are routed to Conn.rxq)
axdown
chan
struct
{}
// ready when accept is marked as no longer operational
axdown1
sync
.
Once
// CloseAccept may be called severall times
...
...
@@ -95,16 +95,16 @@ type Conn struct {
link
*
NodeLink
connId
uint32
rxq
chan
*
PktBuf
// received packets for this Conn go here
txerr
chan
error
// transmit results for this Conn go back here
//
txerr chan error // transmit results for this Conn go back here
txdown
chan
struct
{}
// ready when Conn TX is marked as no longer operational
//
txdown chan struct{} // ready when Conn TX is marked as no longer operational
rxdown
chan
struct
{}
// ----//---- RX
txdownOnce
sync
.
Once
// tx shutdown may be called by both Close and nodelink.shutdown
//
txdownOnce sync.Once // tx shutdown may be called by both Close and nodelink.shutdown
rxdownOnce
sync
.
Once
// ----//----
rxerrOnce
sync
.
Once
// rx error is reported only once - then it is link down or closed
rxclosed
int32
// whether CloseRecv was called
txclosed
int32
// whether CloseSend was called
//
txclosed int32 // whether CloseSend was called
errMsg
*
Error
// error message for peer if rx is down
...
...
@@ -176,7 +176,7 @@ func newNodeLink(conn net.Conn, role LinkRole) *NodeLink {
connTab
:
map
[
uint32
]
*
Conn
{},
nextConnId
:
nextConnId
,
acceptq
:
make
(
chan
*
Conn
),
// XXX +buf
txq
:
make
(
chan
txReq
),
//
txq: make(chan txReq),
axdown
:
make
(
chan
struct
{}),
down
:
make
(
chan
struct
{}),
}
...
...
@@ -195,8 +195,8 @@ func (nl *NodeLink) newConn(connId uint32) *Conn {
c
:=
&
Conn
{
link
:
nl
,
connId
:
connId
,
rxq
:
make
(
chan
*
PktBuf
,
1
),
// NOTE non-blocking - see serveRecv XXX +buf
txerr
:
make
(
chan
error
,
1
),
// NOTE non-blocking - see Conn.Send
txdown
:
make
(
chan
struct
{}),
//
txerr: make(chan error, 1), // NOTE non-blocking - see Conn.Send
//
txdown: make(chan struct{}),
rxdown
:
make
(
chan
struct
{}),
}
nl
.
connTab
[
connId
]
=
c
...
...
@@ -328,9 +328,9 @@ func (c *Conn) shutdown() {
}
func
(
c
*
Conn
)
shutdownTX
()
{
c
.
txdownOnce
.
Do
(
func
()
{
close
(
c
.
txdown
)
})
//
c.txdownOnce.Do(func() {
//
close(c.txdown)
//
})
}
// shutdownRX marks .rxq as no loner operational
...
...
@@ -389,7 +389,7 @@ func (c *Conn) Close() error {
nl
:=
c
.
link
c
.
closeOnce
.
Do
(
func
()
{
atomic
.
StoreInt32
(
&
c
.
rxclosed
,
1
)
atomic
.
StoreInt32
(
&
c
.
txclosed
,
1
)
//
atomic.StoreInt32(&c.txclosed, 1)
c
.
shutdown
()
// adjust link.connTab
...
...
@@ -655,6 +655,7 @@ type txReq struct {
errch
chan
error
}
/*
// errSendShutdown returns appropriate error when c.txdown is found ready in Send
func (c *Conn) errSendShutdown() error {
switch {
...
...
@@ -672,6 +673,7 @@ func (c *Conn) errSendShutdown() error {
return ErrLinkDown
}
}
*/
// sendPkt sends raw packet via connection.
//
...
...
@@ -686,6 +688,7 @@ func (c *Conn) sendPkt(pkt *PktBuf) error {
// https://github.com/golang/go/blob/go1.9-3-g099336988b/src/net/net.go#L109
// https://github.com/golang/go/blob/go1.9-3-g099336988b/src/internal/poll/fd_unix.go#L14
///*
func
(
c
*
Conn
)
sendPkt2
(
pkt
*
PktBuf
)
error
{
// set pkt connId associated with this connection
pkt
.
Header
()
.
ConnId
=
hton32
(
c
.
connId
)
...
...
@@ -702,6 +705,7 @@ func (c *Conn) sendPkt2(pkt *PktBuf) error {
return
err
}
//*/
/*
func (c *Conn) sendPkt2(pkt *PktBuf) error {
...
...
@@ -1216,7 +1220,8 @@ func (c *Conn) Recv() (Msg, error) {
return
msg
,
nil
}
// Send sends message
// Send sends message.
//
// it encodes message into packet and sends it
func
(
c
*
Conn
)
Send
(
msg
Msg
)
error
{
traceConnSendPre
(
c
,
msg
)
...
...
go/neo/t/.gitignore
View file @
814a1fa8
/log
/var
/zsha1
go/neo/t/t.sh
View file @
814a1fa8
...
...
@@ -77,7 +77,7 @@ Sgo() {
# -cpuprofile cpu.out
# -trace trace.out
exec
-a
Sgo
\
neo
-log_dir
=
$log
storage
-cluster
=
$cluster
-bind
=
$Sbind
-masters
=
$Mbind
"
$@
"
&
neo
-
trace
trace.out
-
log_dir
=
$log
storage
-cluster
=
$cluster
-bind
=
$Sbind
-masters
=
$Mbind
"
$@
"
&
}
...
...
go/neo/t/zsha1.go
View file @
814a1fa8
...
...
@@ -8,6 +8,9 @@ import (
"crypto/sha1"
"flag"
"fmt"
"hash"
"hash/crc32"
"hash/adler32"
//"os"
"time"
...
...
@@ -100,12 +103,25 @@ func zsha1(ctx context.Context, url string, useprefetch bool) (err error) {
}
before
:=
lastTid
+
1
// XXX overflow ?
if
false
{
defer
profile
.
Start
(
profile
.
TraceProfile
)
.
Stop
()
if
true
{
//defer profile.Start(profile.TraceProfile).Stop()
defer
profile
.
Start
()
.
Stop
()
}
for
qqq
:=
0
;
qqq
<
10
;
qqq
++
{
tstart
:=
time
.
Now
()
m
:=
sha1
.
New
()
var
m
hash
.
Hash
hashName
:=
"crc32"
switch
hashName
{
case
"sha1"
:
m
=
sha1
.
New
()
case
"crc32"
:
m
=
crc32
.
NewIEEE
()
case
"adler32"
:
m
=
adler32
.
New
()
default
:
panic
(
0
)
// XXX
}
oid
:=
zodb
.
Oid
(
0
)
nread
:=
0
...
...
@@ -142,8 +158,9 @@ loop:
if
useprefetch
{
x
+=
" +prefetch"
}
fmt
.
Printf
(
"%x ; oid=0..%d nread=%d t=%s (%s / object) x=%s
\n
"
,
m
.
Sum
(
nil
),
oid
-
1
,
nread
,
δt
,
δt
/
time
.
Duration
(
oid
),
x
)
// XXX /oid cast ?
fmt
.
Printf
(
"%s:%x ; oid=0..%d nread=%d t=%s (%s / object) x=%s
\n
"
,
hashName
,
m
.
Sum
(
nil
),
oid
-
1
,
nread
,
δt
,
δt
/
time
.
Duration
(
oid
),
x
)
// XXX /oid cast ?
}
return
nil
}
go/neo/t/zsha1.py
View file @
814a1fa8
...
...
@@ -9,9 +9,38 @@ from ZODB.POSException import POSKeyError
from
ZODB.utils
import
p64
,
u64
import
hashlib
from
zlib
import
crc32
,
adler32
import
sys
from
time
import
time
# crc32 in hashlib interface
class
CRC32Hasher
:
name
=
"crc32"
def
__init__
(
self
):
self
.
h
=
crc32
(
''
)
def
update
(
self
,
data
):
self
.
h
=
crc32
(
data
,
self
.
h
)
def
hexdigest
(
self
):
return
'%x'
%
(
self
.
h
&
0xffffffff
)
# adler32 in hashlib interface
class
Adler32Hasher
:
name
=
"adler32"
def
__init__
(
self
):
self
.
h
=
adler32
(
''
)
def
update
(
self
,
data
):
self
.
h
=
adler32
(
data
,
self
.
h
)
def
hexdigest
(
self
):
return
'%x'
%
(
self
.
h
&
0xffffffff
)
def
main
():
url
=
sys
.
argv
[
1
]
...
...
@@ -19,8 +48,12 @@ def main():
last_tid
=
stor
.
lastTransaction
()
before
=
p64
(
u64
(
last_tid
)
+
1
)
for
zzz
in
range
(
10
):
#m = hashlib.sha1()
m
=
CRC32Hasher
()
#m = Adler32Hasher()
tstart
=
time
()
m
=
hashlib
.
sha1
()
oid
=
0
nread
=
0
...
...
@@ -41,8 +74,8 @@ def main():
tend
=
time
()
dt
=
tend
-
tstart
print
(
'
%s ; oid=0..%d nread=%d t=%.3fs (%.1fμs / object) x=zsha1.py'
%
\
(
m
.
hexdigest
(),
oid
-
1
,
nread
,
dt
,
dt
*
1E6
/
oid
))
print
(
'%s:
%s ; oid=0..%d nread=%d t=%.3fs (%.1fμs / object) x=zsha1.py'
%
\
(
m
.
name
,
m
.
hexdigest
(),
oid
-
1
,
nread
,
dt
,
dt
*
1E6
/
oid
))
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment