Hi,
I am using net.Listen("tcp", addr) for a small server program which is to accept data and STORE it on the server.
On the client side, I have a c++ program and I have simply written 4096000 BYTES to the socket (connected to my server program)
The write on the client side finishes in less than a second.
When using the Read() funtions of the connection net.Conn, the read happens very slow.
Following is the Read() for loop :
// Handle the readsvar tbuf [81920]byte
for {n, err := c.rwc.Read(tbuf[0:])// Was there an error in reading ?if err != nil {log.Printf("Could not read packet : %s", err.Error())break}
log.Println(n)
}
returnc.rwc is of type net.Conn--
The output of the above code is as follows :
2012/12/29 13:45:12 16384
2012/12/29 13:45:12 16018
2012/12/29 13:45:12 16384
2012/12/29 13:45:12 16016
2012/12/29 13:45:13 16384
2012/12/29 13:45:13 16016
2012/12/29 13:45:13 16384
2012/12/29 13:45:13 16016
2012/12/29 13:45:13 16384
2012/12/29 13:45:13 16016
2012/12/29 13:45:13 16384
2012/12/29 13:45:13 16016
2012/12/29 13:45:13 16384
2012/12/29 13:45:13 16016
2012/12/29 13:45:13 16384
2012/12/29 13:45:13 16016
2012/12/29 13:45:13 16384
2012/12/29 13:45:14 16016
2012/12/29 13:45:14 16384
2012/12/29 13:45:14 16016
2012/12/29 13:45:14 16384
2012/12/29 13:45:14 16016
2012/12/29 13:45:14 16384
2012/12/29 13:45:14 16016
2012/12/29 13:45:14 16384
2012/12/29 13:45:14 16016
2012/12/29 13:45:14 16384
2012/12/29 13:45:14 16016
2012/12/29 13:45:14 16384
2012/12/29 13:45:14 16016
2012/12/29 13:45:15 16384
2012/12/29 13:45:15 16016
2012/12/29 13:45:15 16384
2012/12/29 13:45:15 16016
2012/12/29 13:45:15 16384
2012/12/29 13:45:15 16016
2012/12/29 13:45:15 16384
2012/12/29 13:45:15 16016
2012/12/29 13:45:15 16384
2012/12/29 13:45:15 16016
2012/12/29 13:45:15 16384
2012/12/29 13:45:15 16016
2012/12/29 13:45:15 16384
2012/12/29 13:45:16 16016
2012/12/29 13:45:16 16384
2012/12/29 13:45:16 16016
2012/12/29 13:45:16 16384
2012/12/29 13:45:16 16016
2012/12/29 13:45:16 16384
2012/12/29 13:45:16 16016
2012/12/29 13:45:16 16384
2012/12/29 13:45:16 16016
2012/12/29 13:45:18 16384
2012/12/29 13:45:18 16016
2012/12/29 13:45:19 16384
2012/12/29 13:45:19 16016
2012/12/29 13:45:19 16384
2012/12/29 13:45:19 16016
2012/12/29 13:45:19 16384
2012/12/29 13:45:19 16016
2012/12/29 13:45:19 16384
2012/12/29 13:45:19 16016
2012/12/29 13:45:19 16384
2012/12/29 13:45:19 16016
2012/12/29 13:45:19 16384
2012/12/29 13:45:19 16016
2012/12/29 13:45:19 16384
2012/12/29 13:45:20 16016
2012/12/29 13:45:20 16384
2012/12/29 13:45:20 16016
2012/12/29 13:45:20 16384
2012/12/29 13:45:20 16016
2012/12/29 13:45:20 16384
2012/12/29 13:45:20 16016
2012/12/29 13:45:20 16384
2012/12/29 13:45:20 16016
2012/12/29 13:45:20 16384
2012/12/29 13:45:20 16016
2012/12/29 13:45:20 16384
2012/12/29 13:45:20 16016
2012/12/29 13:45:21 16384
2012/12/29 13:45:21 16016
2012/12/29 13:45:21 16384
2012/12/29 13:45:21 16016
2012/12/29 13:45:21 16384
2012/12/29 13:45:21 16016
2012/12/29 13:45:21 16384
2012/12/29 13:45:21 16016
2012/12/29 13:45:21 16384
2012/12/29 13:45:21 16016
2012/12/29 13:45:21 16384
2012/12/29 13:45:21 16016
2012/12/29 13:45:21 16384
2012/12/29 13:45:22 16016
2012/12/29 13:45:22 16384
2012/12/29 13:45:22 16016
2012/12/29 13:45:22 16384
2012/12/29 13:45:22 16016
2012/12/29 13:45:22 16384
2012/12/29 13:45:22 16016
2012/12/29 13:45:22 16384
2012/12/29 13:45:22 16016
2012/12/29 13:45:22 16384
2012/12/29 13:45:22 16016
2012/12/29 13:45:22 16384
2012/12/29 13:45:22 16016
2012/12/29 13:45:23 16384
2012/12/29 13:45:23 16016
2012/12/29 13:45:23 16384
2012/12/29 13:45:23 16016
2012/12/29 13:45:23 16384
2012/12/29 13:45:23 16016
2012/12/29 13:45:23 16384
2012/12/29 13:45:23 16016
2012/12/29 13:45:23 16384
2012/12/29 13:45:23 16016
2012/12/29 13:45:23 16384
2012/12/29 13:45:23 16016
2012/12/29 13:45:24 16384
2012/12/29 13:45:24 16016
2012/12/29 13:45:24 16384
2012/12/29 13:45:24 16016
2012/12/29 13:45:24 16384
2012/12/29 13:45:24 16016
2012/12/29 13:45:24 16384
2012/12/29 13:45:24 16016
2012/12/29 13:45:24 16384
2012/12/29 13:45:24 16016
2012/12/29 13:45:24 16384
2012/12/29 13:45:24 16016
2012/12/29 13:45:24 16384
2012/12/29 13:45:25 16016
2012/12/29 13:45:25 16384
2012/12/29 13:45:25 16016
2012/12/29 13:45:25 16384
2012/12/29 13:45:25 16016
2012/12/29 13:45:25 16384
2012/12/29 13:45:25 16016
2012/12/29 13:45:25 16384
2012/12/29 13:45:25 16016
2012/12/29 13:45:25 16384
2012/12/29 13:45:25 16016
2012/12/29 13:45:25 16384
2012/12/29 13:45:26 16016
2012/12/29 13:45:26 16384
2012/12/29 13:45:26 16016
2012/12/29 13:45:26 16384
2012/12/29 13:45:26 16016
2012/12/29 13:45:26 16384
2012/12/29 13:45:26 16016
2012/12/29 13:45:26 16384
2012/12/29 13:45:26 16016
2012/12/29 13:45:26 16384
2012/12/29 13:45:26 16016
2012/12/29 13:45:26 16384
2012/12/29 13:45:26 16016
2012/12/29 13:45:27 16384
2012/12/29 13:45:27 16016
2012/12/29 13:45:27 16384
2012/12/29 13:45:27 16016
2012/12/29 13:45:27 16384
2012/12/29 13:45:27 16016
2012/12/29 13:45:27 16384
2012/12/29 13:45:27 16016
2012/12/29 13:45:27 16384
2012/12/29 13:45:28 16016
2012/12/29 13:45:28 16384
2012/12/29 13:45:29 16016
2012/12/29 13:45:29 16384
2012/12/29 13:45:29 16016
2012/12/29 13:45:29 16384
2012/12/29 13:45:29 16016
2012/12/29 13:45:29 16384
2012/12/29 13:45:29 16016
2012/12/29 13:45:29 16384
2012/12/29 13:45:29 16016
2012/12/29 13:45:29 16384
2012/12/29 13:45:29 16016
2012/12/29 13:45:29 16384
2012/12/29 13:45:30 16016
2012/12/29 13:45:30 16384
2012/12/29 13:45:30 16016
2012/12/29 13:45:30 16384
2012/12/29 13:45:30 16016
2012/12/29 13:45:30 16384
2012/12/29 13:45:30 16016
2012/12/29 13:45:30 16384
2012/12/29 13:45:30 16016
2012/12/29 13:45:31 16384
2012/12/29 13:45:31 16016
2012/12/29 13:45:31 16384
2012/12/29 13:45:31 16016
2012/12/29 13:45:32 16384
2012/12/29 13:45:32 16016
2012/12/29 13:45:32 16384
2012/12/29 13:45:32 16016
2012/12/29 13:45:32 16384
2012/12/29 13:45:32 16016
2012/12/29 13:45:32 16384
2012/12/29 13:45:32 16016
2012/12/29 13:45:32 16384
2012/12/29 13:45:32 16016
2012/12/29 13:45:32 16384
2012/12/29 13:45:32 16016
2012/12/29 13:45:32 16384
2012/12/29 13:45:33 16016
2012/12/29 13:45:33 16384
2012/12/29 13:45:33 16016
2012/12/29 13:45:33 16384
2012/12/29 13:45:33 16016
2012/12/29 13:45:33 16384
2012/12/29 13:45:33 16016
2012/12/29 13:45:33 16384
2012/12/29 13:45:33 16016
2012/12/29 13:45:33 16384
2012/12/29 13:45:33 16016
2012/12/29 13:45:33 16384
2012/12/29 13:45:34 16016
2012/12/29 13:45:34 16384
2012/12/29 13:45:34 16016
2012/12/29 13:45:34 16384
2012/12/29 13:45:34 16016
2012/12/29 13:45:34 16384
2012/12/29 13:45:34 16016
2012/12/29 13:45:34 16384
2012/12/29 13:45:34 16016
2012/12/29 13:45:34 16384
2012/12/29 13:45:34 16016
2012/12/29 13:45:34 16384
2012/12/29 13:45:35 16016
2012/12/29 13:45:35 16384
2012/12/29 13:45:35 16016
2012/12/29 13:45:35 16384
2012/12/29 13:45:35 16016
2012/12/29 13:45:35 16384
2012/12/29 13:45:35 16016
2012/12/29 13:45:36 16384
2012/12/29 13:45:36 16016
2012/12/29 13:45:36 16384
2012/12/29 13:45:36 16016
2012/12/29 13:45:37 16384
2012/12/29 13:45:37 16016
2012/12/29 13:45:37 16384
2012/12/29 13:45:37 16016
2012/12/29 13:45:37 16384
2012/12/29 13:45:37 16016
2012/12/29 13:45:37 16384
2012/12/29 13:45:37 16016
2012/12/29 13:45:37 16384
2012/12/29 13:45:37 16016
2012/12/29 13:45:37 4048
As you can see the read operation is taking nearly 21-25 seconds to read 4096000 bytes,
which is very slow as the server and the client are on the same computer.
Is the read operation wrong ? I am unable to understand why is this so slow ?
// Was the login successful ?
if(unconnected){
qDebug() << socket->state();
return;
}
socket->write("A 4096 BYTE string")
written++;
}
func (c *conn) readRequest() (w *response, err error) {
if c.hijacked {
return nil, ErrHijacked
}
c.lr.N = int64(c.server.maxHeaderBytes()) + 4096 /* bufio slop */
var req *Request
if req, err = ReadRequest(c.buf.Reader); err != nil {
if err.Error() == "STOREDATA" {
c.storedata()
}
if c.lr.N == 0 {
return nil, errTooLarge
}
return nil, err
}
c.lr.N = noLimit
req.RemoteAddr = c.remoteAddr
req.TLS = c.tlsState
w = new(response)
w.conn = c
w.req = req
w.header = make(Header)
w.contentLength = -1
c.body = c.body[:0]
return w, nil
}
// Function to handle the request of STOREDATA
func (c *conn) storedata() {
// Is this a secure connection
if c.tlsState == nil {
fmt.Fprintf(c.rwc, "Connection not secure")
return
}
var tbuf [81920]byte
for { n, err := c.rwc.Read(tbuf[0:])
// Was there an error in reading ? if err != nil {
log.Printf("Could not read packet : %s", err.Error()) break } log.Println(n) } return
if (!socket->waitForEncrypted()) {
qDebug() << "waitForEncrypted Error" << socket->errorString();
return; // An error occured
}
// This is the Storedata request
socket->write("STOREDATA\r\n");
socket->write("A 4096 BYTE string")
written++;
}
Hi,
I am using net.Listen("tcp", addr) for a small server program which is to accept data and STORE it on the server.
On the client side, I have a c++ program and I have simply written 4096000 BYTES to the socket (connected to my server program)
The write on the client side finishes in less than a second.
When using the Read() funtions of the connection net.Conn, the read happens very slow.
Following is the Read() for loop :
// Handle the reads
var tbuf [81920]byte
for {n, err := c.rwc.Read(tbuf[0:])// Was there an error in reading ?if err != nil {log.Printf("Could not read packet : %s", err.Error())break}
log.Println(n)
}
return
c.rwc is of type net.Conn
--
--
>>Why are you editing net/http? If you're interested in benchmarking a connection, just do it in main() with a net.Listen (or the SSL equivalent).