Quantcast
Are you the publisher? Claim or contact us about this channel


Embed this content in your HTML

Search

Report adult content:

click to rate:

Account: (login)

More Channels


Showcase


Channel Catalog



Channel Description:

ClearScript is a library that makes it easy to add scripting to your .NET applications. It currently supports JavaScript (via V8 and JScript) and VBScript.

older | 1 | .... | 31 | 32 | (Page 33) | 34 | 35 | .... | 115 | newer

    0 0

    Hi,

    While investigating some memory related issues in my application, I managed to reproduce what seems to be a problem. The following minimal application terminates on my PC after ~50 cycles and prints the following to console:

    ```
    #
    # Fatal error in heap setup
    # Allocation failed - process out of memory
    #
    ```

    ```
    class Program
    {
    static void Main(string[] args)
    {
    for (int i = 0; i < 1000; i++)
    {
    using (V8ScriptEngine engine = new V8ScriptEngine())
    {
    Console.WriteLine("Created engine #{0}", i);
    engine.Execute("function zz(){}");
    var tmp = engine.Evaluate("zz");
    }
    }
    }
    }
    ```


    Strangely, the memory usage doesn't seem high when it terminates.

    I used both a Nuget package, and a manually built latest ClearScript + V8 with same results.

    Any help will be greatly appreciated.
    Thanks in advance again,
    Ron

    Comments: Hi Ron, First, we agree that there's a problem here. Script objects are not usable after the engine is disposed, so there's no reason for them to keep the V8 runtime alive beyond that point. We're working on a fix, and we'll use this issue to track it. Now, to answer your questions: ​ >I think that in a realistic scenario it would not always be possible to dispose the script object at that time. ​ Yes, it can be inconvenient, but again, in most situations it isn't necessary, as the managed garbage collector eventually takes care of it. In server scenarios we recommend using a fixed-capacity pool of V8 runtimes - an approach that avoids this issue and should yield the best performance. Also, server processes are usually 64-bit, so address space exhaustion is not a concern for them. ​ >You wrote that "V8 reserves a large block of address space for each one" but I'm creating a new engine each time. ​ At the end of each loop iteration the V8 runtime is being held by both the engine and the script object, so both must be disposed or finalized for the V8 runtime to be destroyed. You were disposing only the engine, so with multiple iterations the V8 runtimes piled up, and the managed garbage collector never got a chance to finalize the script objects before your process ran out of address space. ​ >I verified that I can create more than 50 script items per engine, so where exactly is this ~50 limit? ​ The large address space reservation is per V8 runtime, not per script object. Each V8 runtime reserves at least 16MB of address space at a 32MB boundary, so the theoretical maximum number of concurrent V8 runtimes in a 32-bit Windows process is 64. The real maximum of course is lower than that and depends on the application's memory usage. Thanks again for reporting this issue!

    0 0

    Hello ClearScript,

    what I initially wanted was something like require in node.js:
    Node.js
    var app = require('modulename');
    
    app.Method(...)
    
    MyApp
    externals.use('modulename'); // loads the script modulename and put it by _Evaluate_ to the running instance of the script engine
    
    ... usage...
    I hoped to get a little more separation what it is in the app variable. Instead of require I had a package manager, who compiled the script that modulename refers. But I didn't find any way to use it (i.e. call a method explicit within the compiled script). I may add the compiled script to any script engine instance of the same runtime, but I cannot see any other usage for this scenario.

    Meanwhile I think this approach is problematically. Because the compile method compiles only the script that's in the parameter and it will not been executed, something like a composition of scripts will fail when it refer to other objects and/or scripts and will bring to unexpected results because its never apparent what code is currently within the engine execution.

    So it seems like I have to put down my idea and use it as it looks like: compile once and use it in many instances of the script engine.

    Kindly regards,
    Torsten

    0 0

    Hi Torsten,

    If using a JavaScript package manager such as RequireJS is practical in your scenario, then we highly recommend it. These frameworks are specifically designed to manage dependencies, eliminate namespace pollution, and prevent the kind of unpredictable binding that you're concerned about. Have a look here for an example of how RequireJS can be used with ClearScript.

    Good luck!

    0 0

    If a .NET or V8 string has an embedded null character, ClearScript truncates it during marshaling.
    Comments: Fix posted [here](https://clearscript.codeplex.com/SourceControl/changeset/19bc6944c314779ddfe03bcaafa1649785d57a2d).

    0 0

    Hi,

    While investigating some memory related issues in my application, I managed to reproduce what seems to be a problem. The following minimal application terminates on my PC after ~50 cycles and prints the following to console:

    ```
    #
    # Fatal error in heap setup
    # Allocation failed - process out of memory
    #
    ```

    ```
    class Program
    {
    static void Main(string[] args)
    {
    for (int i = 0; i < 1000; i++)
    {
    using (V8ScriptEngine engine = new V8ScriptEngine())
    {
    Console.WriteLine("Created engine #{0}", i);
    engine.Execute("function zz(){}");
    var tmp = engine.Evaluate("zz");
    }
    }
    }
    }
    ```


    Strangely, the memory usage doesn't seem high when it terminates.

    I used both a Nuget package, and a manually built latest ClearScript + V8 with same results.

    Any help will be greatly appreciated.
    Thanks in advance again,
    Ron

    Comments: Fix posted [here](https://clearscript.codeplex.com/SourceControl/changeset/2b42003f6e25f0734829afd6037750172c5d1902).

    0 0

    Hi ClearScript,

    I use ClearScript with V8 in our WCF service and use IIS (Version 7.5) to host the WCF. I have already install VS C++ 2012 redistributable (both x86 and x64), VS C++ 2013 redistributable (both x86 and x64). And put the ClearScriptV8-32.dll, ClearScriptV8-64.dll, v8-ia32.dll, v8-x64.dll to the root folder of the WCF application. However, when I run the service operation, it throw an exception telling that Cannot load V8 interface assembly.

    Could you figure out what I did wrong?

    0 0

    Greetings!

    First of all, sorry about the less-than-helpful error message. In the next release of ClearScript the exception will include detailed information about the directories searched and the errors encountered.

    Anyway, it sounds like you have most things set up correctly. Please make sure that those assemblies are marked as "Do not copy" and that your bin directory does not contain copies of them.

    The only other problems we've seen in deployments like this were all due to permissions. The assemblies were in the right place but the application pool identity couldn't access them. If you're still seeing the exception, can you try running your application under a less restricted identity?

    Good luck!

    0 0

    After prototyping and testing ClearScript, it turns out not to be a good fit for us. Thinking about it, I realize it should have been obvious to me that the goals of the project are far different from our scenario. Neither is good or bad, just different.


    Just to document this for others: If you don't pass in any parameters nor make any calls back to .Net from JS, ClearScript using V8 is much faster while in JS land, twice as fast as IronJS in my simple tests. I'm sure it would be even faster if you were using even moderately complicated JS code. This is a great scenario for using ClearScript!

    However our object model deals with very large datasets with very complex behavior. It is entirely impractical to "lob objects" across the V8 boundary to JS. That means we end up with a lot of calls being proxied back and forth between .Net and V8. That would be bad enough but the behavior of dynamic is also slow and the primary use for me is getting a delegate out that will invoke some JS when called, meaning every invocation goes through dynamic; in some cases I can be making this transition millions of times, and the average JS script itself probably makes 20-50 calls back into .Net, so the total boundary transitions are a quarter of a billion in the worst case. (Basically I tell my customers: "this is what your JS script looks like: function theScript(param1, param2, param3, param4, param5) { }; fill in the body and return me an [Array, string, number, bool]", then I invoke theScript() where required, except there may be dozens or hundreds of these for various scenarios.)

    I tried various schemes and benchmarked against IronJS and IronJS was just way faster - by an order of magnitude or even multiple orders of magnitude in some cases. I tried pre-registering my object type and using attributes to control the proxying behavior (to avoid the reflection hit on every call) but it just couldn't get close to closing the gap. The more .Net objects I pass in to the JS function, the worse the gap. The more calls JS makes back to .Net, the worse the gap.

    To use V8 and do what I want to do would require a different approach, one that allowed fast function calls between the two worlds, and that allowed me to pre-register all types during setup so there is no reflection and no use of dynamic. Obviously that is far different from the goals of the ClearScript project!


    I do want to say thank-you to whoever the anonymous Microsoft-ians are who work on this project. It is much appreciated, even though it isn't useful for my scenario.


    Side note: I wish Microsoft would put some resources into making JS a first-class citizen for these scenarios. If I want to host a JS runtime and compile JS into "native" methods for that platform, on Java I have Rhino/Nashorn that "compile" JS into JVM byte code (Nashorn is very much like IronJS actually). On iOS/Mac, I have JavaScriptCore, though Objective-C is native already. But for .Net environments, there aren't any good options and none supported, even in the form of open-source funding. Unfortunately the IronJS project is dead since Fredrik hasn't been making commits in over a year; can't blame him, working for free after all! I may have to block out some time to learn F# and work on it.

    0 0

    Hi,

    While investigating some memory related issues in my application, I managed to reproduce what seems to be a problem. The following minimal application terminates on my PC after ~50 cycles and prints the following to console:

    ```
    #
    # Fatal error in heap setup
    # Allocation failed - process out of memory
    #
    ```

    ```
    class Program
    {
    static void Main(string[] args)
    {
    for (int i = 0; i < 1000; i++)
    {
    using (V8ScriptEngine engine = new V8ScriptEngine())
    {
    Console.WriteLine("Created engine #{0}", i);
    engine.Execute("function zz(){}");
    var tmp = engine.Evaluate("zz");
    }
    }
    }
    }
    ```


    Strangely, the memory usage doesn't seem high when it terminates.

    I used both a Nuget package, and a manually built latest ClearScript + V8 with same results.

    Any help will be greatly appreciated.
    Thanks in advance again,
    Ron

    Comments: Hi, Thanks for fix! I verified it solved the problem above. Does this fix mean that V8ScriptEngine.Dispose() documentation > After calling Dispose(), you must release all references to the script engine so the garbage collector can reclaim the memory that the script engine was occupying. is no longer needed, and ClearScript handles all required releases? Thanks, Ron

    0 0

    Thank you for your reply.

    I have confirmed that I did not copy those dlls to bin directory. I tried to change the application pool identity to "Local service", "Local system", "ApplicationPoolIdentity" and also administrator account. The problem is still there.

    0 0

    Hello xenadu,

    It does sound like ClearScript isn't quite what you're looking for, as it heavily favors interop simplicity over performance. If reflection is a deal breaker, then ClearScript is definitely not for you.

    Thanks for giving ClearScript a shot, and good luck!

    0 0

    Hi,

    While investigating some memory related issues in my application, I managed to reproduce what seems to be a problem. The following minimal application terminates on my PC after ~50 cycles and prints the following to console:

    ```
    #
    # Fatal error in heap setup
    # Allocation failed - process out of memory
    #
    ```

    ```
    class Program
    {
    static void Main(string[] args)
    {
    for (int i = 0; i < 1000; i++)
    {
    using (V8ScriptEngine engine = new V8ScriptEngine())
    {
    Console.WriteLine("Created engine #{0}", i);
    engine.Execute("function zz(){}");
    var tmp = engine.Evaluate("zz");
    }
    }
    }
    }
    ```


    Strangely, the memory usage doesn't seem high when it terminates.

    I used both a Nuget package, and a manually built latest ClearScript + V8 with same results.

    Any help will be greatly appreciated.
    Thanks in advance again,
    Ron

    Comments: Hi Ron, No, that documentation still applies, although the wording may be a bit clumsy. All it's saying is that even if you've called `Dispose()`, the object cannot be garbage-collected until all references to it are gone. That's just the fundamental behavior of all managed objects. The problem here had to with _unmanaged_ objects - V8 runtimes in particular. Before the fix, script objects and compiled scripts held strong references to their V8 runtimes. Now those references are weak, and only script engines continue to use strong references. The result is that disposing a script engine immediately destroys the V8 runtime (unless that runtime is still in use by other script engines). Thanks again. This was an important fix!

    0 0

    Hi,

    While investigating some memory related issues in my application, I managed to reproduce what seems to be a problem. The following minimal application terminates on my PC after ~50 cycles and prints the following to console:

    ```
    #
    # Fatal error in heap setup
    # Allocation failed - process out of memory
    #
    ```

    ```
    class Program
    {
    static void Main(string[] args)
    {
    for (int i = 0; i < 1000; i++)
    {
    using (V8ScriptEngine engine = new V8ScriptEngine())
    {
    Console.WriteLine("Created engine #{0}", i);
    engine.Execute("function zz(){}");
    var tmp = engine.Evaluate("zz");
    }
    }
    }
    }
    ```


    Strangely, the memory usage doesn't seem high when it terminates.

    I used both a Nuget package, and a manually built latest ClearScript + V8 with same results.

    Any help will be greatly appreciated.
    Thanks in advance again,
    Ron

    Comments: Hi, I ran into the same problem with my project. I downloaded and compiled this fix, and integrated it into my project, but now I am getting the following error: Method 'Execute' in type 'Microsoft.ClearScript.V8.V8ContextProxyImpl' from assembly 'ClearScriptV8-32, Version=5.3.11.0, Culture=neutral, PublicKeyToken=null' does not have an implementation. Is the fix faulty or did I do something wrong? Thank you

    0 0

    Based on your ListExtensions class I've created a slightly modified one:
    public static class ListExtensions
    {
        public static void forEach<T>(this IEnumerable<T> list, dynamic function)
        {
            list.ToList().ForEach(item => function(item));
        }
    }
    This mimics the JavaScript forEach function for native arrays (at least to some degree) and in addition works both for .NET lists and .NET arrays.

    0 0

    hello,

    i am having the same problem with a web aplication running in IIS8 on windows server 2012 x64 standard.

    any ideas ? this is really urgent .

    thank you in advance .

    0 0

    Hi,

    While investigating some memory related issues in my application, I managed to reproduce what seems to be a problem. The following minimal application terminates on my PC after ~50 cycles and prints the following to console:

    ```
    #
    # Fatal error in heap setup
    # Allocation failed - process out of memory
    #
    ```

    ```
    class Program
    {
    static void Main(string[] args)
    {
    for (int i = 0; i < 1000; i++)
    {
    using (V8ScriptEngine engine = new V8ScriptEngine())
    {
    Console.WriteLine("Created engine #{0}", i);
    engine.Execute("function zz(){}");
    var tmp = engine.Evaluate("zz");
    }
    }
    }
    }
    ```


    Strangely, the memory usage doesn't seem high when it terminates.

    I used both a Nuget package, and a manually built latest ClearScript + V8 with same results.

    Any help will be greatly appreciated.
    Thanks in advance again,
    Ron

    Comments: It looks like you may not have rebuilt everything, or you missed some files when integrating the rebuilt libraries into your project. Specifically, it looks like ClearScript.dll and ClearScriptV8-32.dll are out of sync.

    0 0

    Hi,

    While investigating some memory related issues in my application, I managed to reproduce what seems to be a problem. The following minimal application terminates on my PC after ~50 cycles and prints the following to console:

    ```
    #
    # Fatal error in heap setup
    # Allocation failed - process out of memory
    #
    ```

    ```
    class Program
    {
    static void Main(string[] args)
    {
    for (int i = 0; i < 1000; i++)
    {
    using (V8ScriptEngine engine = new V8ScriptEngine())
    {
    Console.WriteLine("Created engine #{0}", i);
    engine.Execute("function zz(){}");
    var tmp = engine.Evaluate("zz");
    }
    }
    }
    }
    ```


    Strangely, the memory usage doesn't seem high when it terminates.

    I used both a Nuget package, and a manually built latest ClearScript + V8 with same results.

    Any help will be greatly appreciated.
    Thanks in advance again,
    Ron

    Comments: Oh, yeah, got it. Thanks for the help!

    0 0

    Hi scharada,

    We have a pending change that improves error reporting for V8 deployment issues. Our plan was to bundle it with the next point release, but that's taking a while, so we'll post it on its own within the next day or so.

    This change will allow you to see the specific errors encountered during the V8 loading procedure, and should give you a pretty good idea about what's going on in your deployment.

    Cheers!

    0 0

    Hi Cheokfan,

    We have a pending change that improves error reporting for V8 deployment issues. Our plan was to bundle it with the next point release, but that's taking a while, so we'll post it on its own within the next day or so.

    This change will allow you to see the specific errors encountered during the V8 loading procedure, and should give you a pretty good idea about what's going on in your deployment.

    Cheers!

    0 0

    Enhanced error reporting for V8 assembly load failures (Issue #39).

older | 1 | .... | 31 | 32 | (Page 33) | 34 | 35 | .... | 115 | newer