-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
Class isc.zlib.Test Extends %Persistent | ||
{ | ||
|
||
Parameter ZLIBID = 4995; | ||
|
||
/// Get path to zlib callout shared library | ||
/// Library assumed to be in bin folder, unless specified otherwise | ||
ClassMethod getLibPath() [ CodeMode = expression ] | ||
{ | ||
$g(^isc.zlib.Test, $g(^%SYS("bindir")) _ "zlibisc." _ $select($$$isWINDOWS:"dll", 1:"so")) | ||
} | ||
|
||
/// Same callout library, but with immediate loading | ||
/// do ##class(isc.zlib.Test).callout3() | ||
ClassMethod callout3(text = "Hello World", rounds As %Integer = 10000) | ||
{ | ||
set path = ..getLibPath() | ||
for i=1:1:rounds{ | ||
kill out | ||
set out = $ZF(-3, path, "Compress", text) | ||
} | ||
do $ZF(-3, "") | ||
} | ||
|
||
/// Done once per system start, so we don't count it. | ||
/// do ##class(isc.zlib.Test).callout6Init() | ||
ClassMethod callout6Init() | ||
{ | ||
set sc = $ZF(-4,6,..#ZLIBID) | ||
set sc = $ZF(-4,5,..#ZLIBID, ..getLibPath()) | ||
} | ||
|
||
/// Callout library, but with system loading | ||
/// do ##class(isc.zlib.Test).callout6() | ||
ClassMethod callout6(text = "Hello World", rounds As %Integer = 10000) | ||
{ | ||
for i=1:1:rounds{ | ||
kill out | ||
set out = $ZF(-6, ..#ZLIBID, 1, text) | ||
} | ||
} | ||
|
||
/// Java GateWay implementation | ||
/// do ##class(isc.zlib.Test).jgw() | ||
ClassMethod jgw(text = "Hello World", rounds As %Integer = 10000) | ||
{ | ||
set gateway = ##class(isc.zlib.Utils).connect() | ||
for i=1:1:rounds{ | ||
kill out | ||
set out = ##class(isc.zlib.Java).compress(gateway, text) | ||
} | ||
} | ||
|
||
/// Default system implementation | ||
/// do ##class(isc.zlib.Test).system() | ||
ClassMethod system(text = "Hello World", rounds As %Integer = 10000) | ||
{ | ||
for i=1:1:rounds{ | ||
kill out | ||
set out = $extract($SYSTEM.Util.Compress(text), 2, *-1) | ||
} | ||
} | ||
|
||
/// NodeJS implementation | ||
/// do ##class(isc.zlib.Test).node() | ||
ClassMethod node(text = "Hello World", rounds As %Integer = 10000) | ||
{ | ||
set req = ##class(%Net.HttpRequest).%New() | ||
set req.Server = "localhost" | ||
set req.Port = 3000 | ||
set req.Location = "/zlibapi/" _ text | ||
|
||
for i=1:1:rounds{ | ||
kill out | ||
set sc = req.Get(,,$$$NO) | ||
set out = req.HttpResponse.Data //.Read($$$MaxStringLength) | ||
} | ||
} | ||
|
||
/// textLength - either text, or a number of symbols in text | ||
/// rounds - number of calls to zlib | ||
/// do ##class(isc.zlib.Test).test() | ||
ClassMethod test(textLength As %Integer = 100, rounds As %Integer = 10000) | ||
{ | ||
set:textLength="" textLength = 100 | ||
|
||
if ($isvalidnum(textLength) && (textLength=$normalize(textLength, 0))) { | ||
set text = ##class(%PopulateUtils).StringMin(textLength, textLength) | ||
} else { | ||
set text = textLength | ||
set textLength = $l(text) | ||
} | ||
|
||
do ..callout6Init() | ||
|
||
write "Text: ", text, ! | ||
write "Text length: ", $l(text), ! | ||
write "Rounds: ", rounds, ! | ||
for method="callout3", "callout6", "system", "jgw", "node" { | ||
set start = $zh | ||
do $classmethod(,method, text, rounds) | ||
set end = $zh | ||
|
||
set time = end - start | ||
|
||
write "Method: ", method, ! | ||
write "Time: ", time, ! | ||
write "Speed (Kb/sec): ", $normalize(textLength*rounds/1024/time, 0), ! | ||
write "Speed (calls/sec): ", $normalize(rounds/time, 0), ! | ||
} | ||
} | ||
|
||
Storage Default | ||
{ | ||
<Data name="TestDefaultData"> | ||
<Value name="1"> | ||
<Value>%%CLASSNAME</Value> | ||
</Value> | ||
</Data> | ||
<DataLocation>^isc.zlib.TestD</DataLocation> | ||
<DefaultData>TestDefaultData</DefaultData> | ||
<IdLocation>^isc.zlib.TestD</IdLocation> | ||
<IndexLocation>^isc.zlib.TestI</IndexLocation> | ||
<StreamLocation>^isc.zlib.TestS</StreamLocation> | ||
<Type>%Library.CacheStorage</Type> | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Class isc.zlib.Utils | ||
{ | ||
|
||
Parameter CLASS = "isc.zlib.Java"; | ||
|
||
Parameter CLASSPATH = {$g(^%SYS("bindir")) _ "zlib.jar"}; | ||
|
||
Parameter GATEWAY = "ZLIB"; | ||
|
||
/// Create JGW. Java home must point to 1.8 jre. | ||
/// Write $System.Status.GetErrorText(##class(isc.zlib.Utils).createGateway()) | ||
ClassMethod createGateway(gatewayName = {..#GATEWAY}, javaHome = {$SYSTEM.Util.GetEnviron("JAVA_HOME")}, path As %String = {..#CLASSPATH}, port As %Integer = 55559) | ||
{ | ||
set sys = ##class(%Net.Remote.ObjectGateway).%New() | ||
set sys.Name = gatewayName | ||
set sys.Type = 1 | ||
set sys.JavaHome = javaHome | ||
set sys.ClassPath = path | ||
set sys.Port = port | ||
quit sys.%Save() | ||
} | ||
|
||
/// Load Jar from path. | ||
/// Write $System.Status.GetErrorText(##class(isc.zlib.Utils).updateJar()) | ||
ClassMethod updateJar(gatewayName = {..#GATEWAY}, path As %String = {..#CLASSPATH}) | ||
{ | ||
#Dim sc As %Status = $$$OK | ||
|
||
set sc = ##class(%Net.Remote.Service).StopGateway(gatewayName) | ||
|
||
set gateway = ..connect(gatewayName, path, .sc) | ||
quit:$$$ISERR(sc) sc | ||
|
||
set sc = gateway.%Import(..#CLASS) | ||
quit:$$$ISERR(sc) sc | ||
set:'##class(%Dictionary.CompiledClass).%ExistsId(..#CLASS) sc = $$$ERROR($$$GeneralError, $$$FormatText("Class '%1' does not exist",..#CLASS)) | ||
quit:$$$ISERR(sc) sc | ||
|
||
set sc = ##class(%Net.Remote.Service).StopGateway(gatewayName) | ||
|
||
quit sc | ||
} | ||
|
||
/// Get JGW object | ||
ClassMethod connect(gatewayName As %String = {..#GATEWAY}, path As %String = {..#CLASSPATH}, Output sc As %Status) As %Net.Remote.Gateway | ||
{ | ||
set gateway = "" | ||
set sc = ##class(%Net.Remote.Service).OpenGateway(gatewayName, .gatewayConfig) | ||
quit:$$$ISERR(sc) gateway | ||
set sc = ##class(%Net.Remote.Service).ConnectGateway(gatewayConfig, .gateway, path, $$$YES) | ||
quit gateway | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
isc.zlib.Test.cls | ||
isc.zlib.Utils.cls |