Thread overview | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 27, 2015 problem with gc? | ||||
---|---|---|---|---|
| ||||
I am writing a echoclient, as below: Ptr!Conn conn = connect("127.0.0.1",8881); ubyte[100] buf; for(int i=0; i<N; i++) { scope string str = format("%s",i); conn.write((cast(ubyte*)str.ptr)[0..str.length]); conn.read(buf[0..str.length]); n++; } conn.close(); When it loops about more than 100000 times,the throughput will fall from 60000request/second to 26request/second. If the code changes a little as below: scope string str = format("%s",10000); //changes to a constant It will runs normally with speed of 60000request/second. I test for 13minutes, everything seems well. What happened when the code changes a little? Who will give an explaination,Thanks a lot? |
May 27, 2015 Re: problem with gc? | ||||
---|---|---|---|---|
| ||||
Posted in reply to zhmt | I noticed that the cpu% falls from 99% down to 4% as well when the throughput falls down. |
May 27, 2015 Re: problem with gc? | ||||
---|---|---|---|---|
| ||||
Posted in reply to zhmt | On Wednesday, 27 May 2015 at 05:51:21 UTC, zhmt wrote:
> I noticed that the cpu% falls from 99% down to 4% as well when the throughput falls down.
I tried again for several times, the cpu is still busy, 98.9%.
|
May 27, 2015 Re: problem with gc? | ||||
---|---|---|---|---|
| ||||
Posted in reply to zhmt | On Wednesday, 27 May 2015 at 05:48:13 UTC, zhmt wrote:
> What happened when the code changes a little? Who will give an explaination,Thanks a lot?
Yes, on the first sight it looks like your allocations in the loop make GC spend too much time. I don't think "scope" does anything here. Try adding "delete str;" to the end of the loop, it should do what your "scope" meant. I know it's deprecated but sometimes it's just right.
|
May 27, 2015 Re: problem with gc? | ||||
---|---|---|---|---|
| ||||
Posted in reply to zhmt | On Wednesday, 27 May 2015 at 05:48:13 UTC, zhmt wrote:
> I am writing a echoclient, as below:
>
> Ptr!Conn conn = connect("127.0.0.1",8881);
> ubyte[100] buf;
> for(int i=0; i<N; i++)
> {
> scope string str = format("%s",i);
> conn.write((cast(ubyte*)str.ptr)[0..str.length]);
> conn.read(buf[0..str.length]);
> n++;
> }
> conn.close();
>
>
> When it loops about more than 100000 times,the throughput will fall from 60000request/second to 26request/second.
>
> If the code changes a little as below:
>
> scope string str = format("%s",10000); //changes to a constant
>
> It will runs normally with speed of 60000request/second. I test for 13minutes, everything seems well.
>
>
>
> What happened when the code changes a little? Who will give an explaination,Thanks a lot?
Have you tried to declare str in the upper scope ?
---
Ptr!Conn conn = connect("127.0.0.1",8881);
ubyte[100] buf;
string str;
for(int i=0; i<N; i++)
{
str = format("%s",i);
conn.write(cast(ubyte[]) str);
conn.read(buf[0..str.length]);
n++;
}
conn.close();
---
And also you could try to surround the whole block with `GC.disable` and `GC.enable`. This would help to determine if the GC is involved:
---
Ptr!Conn conn = connect("127.0.0.1",8881);
GC.disable;
ubyte[100] buf;
string str;
for(int i=0; i<N; i++)
{
str = format("%s",i);
conn.write(cast(ubyte[]) str);
conn.read(buf[0..str.length]);
n++;
}
GC.enable;
conn.close();
---
|
May 27, 2015 Re: problem with gc? | ||||
---|---|---|---|---|
| ||||
Posted in reply to zhmt | On Wednesday, 27 May 2015 at 05:48:13 UTC, zhmt wrote: > I am writing a echoclient, as below: > > Ptr!Conn conn = connect("127.0.0.1",8881); > ubyte[100] buf; > for(int i=0; i<N; i++) > { > scope string str = format("%s",i); > conn.write((cast(ubyte*)str.ptr)[0..str.length]); > conn.read(buf[0..str.length]); > n++; > } > conn.close(); You can use sformat http://dlang.org/phobos/std_format.html#.sformat with your buffer. |
May 27, 2015 Re: problem with gc? | ||||
---|---|---|---|---|
| ||||
Posted in reply to zhmt | On Wed, 27 May 2015 05:48:11 +0000 zhmt via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote: > I am writing a echoclient, as below: > > Ptr!Conn conn = connect("127.0.0.1",8881); > ubyte[100] buf; > for(int i=0; i<N; i++) > { > scope string str = format("%s",i); > conn.write((cast(ubyte*)str.ptr)[0..str.length]); > conn.read(buf[0..str.length]); > n++; > } > conn.close(); > > > When it loops about more than 100000 times,the throughput will fall from 60000request/second to 26request/second. > > If the code changes a little as below: > > scope string str = format("%s",10000); //changes to a constant > > It will runs normally with speed of 60000request/second. I test for 13minutes, everything seems well. > > > > What happened when the code changes a little? Who will give an explaination,Thanks a lot? what happend if you use sformat instead? Ptr!Conn conn = connect("127.0.0.1",8881); ubyte[100] buf; char[100] buf2; for(int i=0; i<N; i++) { auto str = sformat(buf2, "%s",i); conn.write((cast(ubyte*)str.ptr)[0..str.length]); conn.read(buf[0..str.length]); n++; } conn.close(); |
May 27, 2015 Re: problem with gc? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Kozák |
>>
>> What happened when the code changes a little? Who will give an explaination,Thanks a lot?
>
> what happend if you use sformat instead?
>
> Ptr!Conn conn = connect("127.0.0.1",8881);
> ubyte[100] buf;
> char[100] buf2;
> for(int i=0; i<N; i++)
> {
> auto str = sformat(buf2, "%s",i);
> conn.write((cast(ubyte*)str.ptr)[0..str.length]);
> conn.read(buf[0..str.length]);
> n++;
> }
> conn.close();
@Daniel Kozák
Thanks for reply.
I have tried sformat, but it doesnt work: throughput falls down, and the cpu keeps busy.
|
May 27, 2015 Re: problem with gc? | ||||
---|---|---|---|---|
| ||||
Posted in reply to jklp | @jklp
>
> And also you could try to surround the whole block with `GC.disable` and `GC.enable`. This would help to determine if the GC is involved:
>
> ---
> Ptr!Conn conn = connect("127.0.0.1",8881);
> GC.disable;
> ubyte[100] buf;
> string str;
> for(int i=0; i<N; i++)
> {
> str = format("%s",i);
> conn.write(cast(ubyte[]) str);
> conn.read(buf[0..str.length]);
> n++;
> }
> GC.enable;
> conn.close();
> ---
I have tried this, and throughput falls down as well too. Does this mean the gc is not involved? I am confused.
|
May 27, 2015 Re: problem with gc? | ||||
---|---|---|---|---|
| ||||
Posted in reply to zhmt | When I enable the --profle, get something like this, it doesnt give me too much help: ======== Timer Is 3579545 Ticks/Sec, Times are in Microsecs ======== Num Tree Func Per Calls Time Time Call 1298756 4996649885 4987577377 3840 int gamelibd.net.linux.TcpLinuxConn.TcpLinuxConn.writeSome(ubyte[]) 30358909 14353678347 4433441425 146 void gamelibd.net.linux.linuxconn.selectAndProcessNetEvents(ulong) 30359249 1670090296 1582462941 52 long gamelibd.util.utcNow() 1298744 874889280 858583339 661 _D8gamelibd3net5linux12TcpLinuxConn12TcpLinuxConn8readSomeMFAhZ9__lambda2MFZv 1300549 25997 803742026 618 int gamelibd.net.linux.TcpLinuxConn.TcpLinuxConn.readSome(ubyte[]) 2597506 756203332 702092233 270 void gamelibd.net.linux.epollapi.changeEv(int, int, void*, int) 30358909 9920075665 285890739 9 void gamelibd.net.linux.linuxconn.handleEvent(gamelibd.net.linux.epollapi.epoll_event[]) 1298744 5131800498 244989946 188 void gamelibd.net.linux.TcpLinuxConn.TcpLinuxConn.doRead(gamelibd.net.linux.epollapi.epoll_event*) 1298768 0 223952199 172 void gamelibd.net.linux.IoEventHandler.IoEventHandler.autoReaderFiberSetting(void delegate()) 1298756 5207337081 210684924 162 int gamelibd.net.linux.TcpLinuxConn.TcpLinuxConn.write(ubyte[]) 30358953 162443804 162443804 5 @property bool gamelibd.util.LinkedList!(gamelibd.net.exceptionsafefiber.ExceptionSafeFiber).LinkedList.isEmpty() 648485 989705094 139972636 215 int gamelibd.net.linux.TcpLinuxConn.TcpLinuxConn.read(ubyte[]) 1298919 1008643391 124807374 96 void gamelibd.net.exceptionsafefiber.ExceptionSafeFiber.resume() 30359072 88431872 88431872 2 pure nothrow @nogc @safe gamelibd.net.exceptionsafefiber.TimerTask std.container.rbtree.__T12RedBlackTreeTC8gamelibd3net18exceptionsafefiber9TimerTaskVAyaa25_612e737461727454696d65203c20622e737461727454696d65Vbi1Z.RedBlackTree.front() 1298750 1574897328 87384898 67 void gamelibd.net.linux.IoEventHandler.IoEventHandler.tryResumeReaderFiber() 30359072 77325915 77325915 2 pure nothrow @property @nogc @safe ulong std.container.rbtree.__T12RedBlackTreeTC8gamelibd3net18exceptionsafefiber9TimerTaskVAyaa25_612e737461727454696d65203c20622e737461727454696d65Vbi1Z.RedBlackTree.length() 4544831 61560347 61560347 13 pure @safe bool std.exception.enforce!(bool).enforce(bool, lazy object.Throwable) 2597500 51905642 51905642 19 void gamelibd.net.linux.TcpLinuxConn.TcpLinuxConn.throwExceptionIfErrAfterOp(long) 1298951 49392056 49392056 38 gamelibd.net.exceptionsafefiber.ExceptionSafeFiber gamelibd.net.exceptionsafefiber.ExceptionSafeFiber.getThis() 2597518 80877181 46297298 17 gamelibd.mem.Ptr!(gamelibd.net.provider.Conn).Ptr.getinout(ref @property inout(gamelibd.net.provider.Conn) function()) 2597693 51725730 37629038 14 gamelibd.mem.Ptr!(gamelibd.net.exceptionsafefiber.ExceptionSafeFiber).Ptr.getinout(ref @property inout(gamelibd.net.exceptionsafefiber.ExceptionSafeFiber) function()) 1298756 479941655 34717468 26 void gamelibd.net.linux.IoEventHandler.IoEventHandler.enableRead() |
Copyright © 1999-2021 by the D Language Foundation