I modified the test code, it will create and destory thread at loop, thread do very simple thing which construct v8::locker and destruct it. I found a few million cycles, the speed thread of execution slow down absolutely, and the memory consumption continues to increase slowly.
#include <pthread.h>
#include <v8.h>
#include <sys/time.h>
double GetTime()
{
timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + (double)tv.tv_usec * 0.000001;
}
v8::Isolate *isolate;
class Thread
{
public:
static void* Start(void *thread)
{
static_cast<Thread*>(thread)->Start_();
}
private:
void Start_()
{
v8::Locker locker(isolate);
}
};
void test(pthread_t tid[], Thread thread[])
{
for (int i = 0; i < 1; ++i)
{
pthread_create(&tid[i], NULL, Thread::Start, &thread[i]);
}
for (int i = 0; i < 1; ++i)
{
pthread_join(tid[i], NULL);
}
}
int main(int argc, char* argv[])
{
v8::V8::Initialize();
isolate = v8::Isolate::New();
{
pthread_t tid[1024];
Thread thread[1024];
for (long long i = 0; i < 1000 * 1000 * 1000 * 1000llu; ++i)
{
double s = GetTime();
test(tid, thread);
printf("%d. %f\n", i+1, GetTime() - s);
}
}
isolate->Dispose();
v8::V8::Dispose();
}
<https://lh6.googleusercontent.com/-k9kAjBeeh88/VI-i2rJ8HUI/AAAAAAAAAII/yCVL0N6tsms/s1600/b1.png>
<https://lh3.googleusercontent.com/-cUaA-JgmfZw/VI-i8qpxvRI/AAAAAAAAAIY/CGTIkf9xZ0A/s1600/b2.png>
<https://lh5.googleusercontent.com/-jYtPKqSoP-o/VI-kLqk3mNI/AAAAAAAAAI4/lG9O689fM2s/s1600/Screenshot%2Bfrom%2B2014-12-16%2B11%3A15%3A42.png>
<https://lh4.googleusercontent.com/-BL-Z1QPCNNg/VI-kXfO76LI/AAAAAAAAAJI/QkeeR2kh-OA/s1600/a2.png>
On Monday, December 15, 2014 8:36:25 PM UTC+8, Jakob Kummerow wrote:
>
> An isolate has a table with per-thread data, which is implemented as a
> linked list and scanned linearly. So yes, when a single isolate has seen
> many threads, locking it will become slower. Since there's typically no
> reason to access the same isolate with thousands of threads, I wouldn't
> consider this a bug.
>
> On Mon, Dec 15, 2014 at 11:42 AM, <[email protected] <javascript:>>
> wrote:
>>
>>
>> <https://lh6.googleusercontent.com/-sPNEtxGhqEc/VI6531u4HQI/AAAAAAAAAHw/2rZtAitF4bM/s1600/Screenshot%2Bfrom%2B2014-12-15%2B18%3A10%3A09.png>
>> My Os is fedora20, v8 version is v8-3.25.30,
>> first loop consumes 0.02 second, and then the 172th's loop consumes
>> 2.48second.
>>
>> #include <pthread.h>
>> #include <v8.h>
>> #include <sys/time.h>
>>
>> double GetTime()
>> {
>> timeval tv;
>> gettimeofday(&tv, NULL);
>> return tv.tv_sec + (double)tv.tv_usec * 0.000001;
>> }
>>
>> v8::Isolate *isolate;
>>
>> class Thread
>> {
>> public:
>> static void* Start(void *thread)
>> {
>> static_cast<Thread*>(thread)->Start_();
>> }
>> private:
>> void Start_()
>> {
>> v8::Locker locker(isolate);
>> v8::Isolate::Scope scope(isolate);
>> }
>>
>> };
>>
>> void test(pthread_t tid[], Thread thread[])
>> {
>> for (int i = 0; i < 1024; ++i)
>> {
>> pthread_create(&tid[i], NULL, Thread::Start, &thread[i]);
>> }
>> for (int i = 0; i < 1024; ++i)
>> {
>> pthread_join(tid[i], NULL);
>> }
>> }
>>
>> int main(int argc, char* argv[])
>> {
>> v8::V8::Initialize();
>> isolate = v8::Isolate::New();
>> {
>> pthread_t tid[1024];
>> Thread thread[1024];
>> for (int i = 0; i < 1000 * 1000 * 1000; ++i)
>> {
>> double s = GetTime();
>> test(tid, thread);
>> printf("%d. %f\n", i+1, GetTime() - s);
>> }
>> }
>> isolate->Dispose();
>> v8::V8::Dispose();
>> }
>>
>> --
>> --
>> v8-dev mailing list
>> [email protected] <javascript:>
>> http://groups.google.com/group/v8-dev
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "v8-dev" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups
"v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
