Ver Fonte

cfml performance tweaks & add missing test (#6387)

* cfml performance tweaks

* Add missing cached test
Brad Wood há 4 anos atrás
pai
commit
9ab0f23352

+ 1 - 0
.gitignore

@@ -126,3 +126,4 @@ obj
 
 # CFML
 frameworks/CFML/coldbox/src/coldbox/
+frameworks/CFML/CFML/src/cachebox/

+ 2 - 0
frameworks/CFML/CFML/benchmark_config.json

@@ -9,6 +9,7 @@
         "fortune_url": "/fortunes.cfm",
         "plaintext_url": "/plaintext.cfm",
         "update_url": "/updates.cfm?queries=",
+        "cached_query_url": "/cached.cfm?count=",
         "port": 8080,
         "approach": "Realistic",
         "classification": "Platform",
@@ -32,6 +33,7 @@
         "fortune_url": "/fortunes.cfm",
         "plaintext_url": "/plaintext.cfm",
         "update_url": "/updates.cfm?queries=",
+        "cached_query_url": "/cached.cfm?count=",
         "port": 8080,
         "approach": "Realistic",
         "classification": "Platform",

+ 4 - 1
frameworks/CFML/CFML/cfml-adobe.dockerfile

@@ -1,9 +1,12 @@
 FROM ortussolutions/commandbox:3.2.1
 
+ENV cfconfig_adminPassword=password
+
 COPY ./src/server-adobe.json /app/server.json
 COPY ./src/.cfconfig.json /app/.cfconfig.json
+COPY ./src/box.json /app/box.json
 
-RUN box install commandbox-cfconfig --verbose --force
+RUN box install --verbose --force
 
 RUN ${BUILD_DIR}/util/warmup-server.sh
 

+ 6 - 1
frameworks/CFML/CFML/cfml.dockerfile

@@ -1,12 +1,17 @@
 FROM ortussolutions/commandbox:3.2.1
 
+ENV cfconfig_adminPassword=password
+
 COPY ./src/server-lucee.json /app/server.json
 COPY ./src/.cfconfig.json /app/.cfconfig.json
+COPY ./src/box.json /app/box.json
 
-RUN box install commandbox-cfconfig --verbose --force
+RUN box install --verbose --force
 
 RUN ${BUILD_DIR}/util/warmup-server.sh
 
+RUN box cfconfig import from=/app/.cfconfig.json toFormat=luceeWeb
+
 RUN export FINALIZE_STARTUP=true;$BUILD_DIR/run.sh;unset FINALIZE_STARTUP
 
 HEALTHCHECK NONE

+ 140 - 1
frameworks/CFML/CFML/src/.cfconfig.json

@@ -12,5 +12,144 @@
     },
     "inspectTemplate":"never",
     "maxCFThreads":"512",
-    "adminPassword":"password"
+    "maxTemplateRequests":"512",
+    "adminPassword":"password",
+    "loggers" : {
+        "scheduler":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/scheduler.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "application":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/application.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "requesttimeout":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/requesttimeout.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "exception":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/exception.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "mapping":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/mapping.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "orm":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/orm.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "deploy":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/deploy.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "trace":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/trace.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "memory":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/memory.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "gateway":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/gateway.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "search":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/search.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "rest":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/rest.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "thread":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/thread.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "scope":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/scope.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "datasource":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/datasource.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "remoteclient":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/remoteclient.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "mail":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/mail.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        }
+    }
 }

+ 21 - 0
frameworks/CFML/CFML/src/Application.cfc

@@ -0,0 +1,21 @@
+component {
+
+	this.datasource = 'world';
+
+    function onApplicationStart() {        
+        application.cacheBox = new cachebox.system.cache.CacheFactory( 'config.CacheBox' );
+
+        var cache = application.cacheBox.getCache( 'default' );
+		cfloop( from="1", to="10000", index="local.i" ) {
+			cache.getOrSet(
+				'cached-world-#i#',
+				()=>queryExecute( '
+					SELECT id, randomNumber
+					FROM World
+					WHERE id = #i#
+				').getRow( 1 )
+			);
+        }
+    }
+
+}

+ 11 - 0
frameworks/CFML/CFML/src/box.json

@@ -0,0 +1,11 @@
+{
+    "name":"My CFML App",
+    "version":"1.0.0",
+    "installPaths":{
+        "cachebox":"cachebox/"
+    },
+    "dependencies":{
+        "cachebox":"^6.0.0",
+        "commandbox-cfconfig":"^1.2.1"
+    }
+}

+ 24 - 0
frameworks/CFML/CFML/src/cached.cfm

@@ -0,0 +1,24 @@
+<cfsetting enablecfoutputonly=true>
+<cfset cache = application.cachebox.getCache( 'default' )>
+<cfparam name="url.count" default="1">
+<cfset url.count = val( url.count )>
+<cfif url.count gt 500 >
+    <cfset url.count = 500>
+<cfelseif url.count lt 1 >
+    <cfset url.count = 1>
+</cfif>
+<cfheader name="Server" value="cfml-lucee">
+<cfheader name="Content-Type" value="application/json">
+<cfset results = []>
+<cfloop from="1" to="#url.count#" index="i">
+    <cfset id = randRange( 1, 10000 )>
+    <cfset qry = cache.getOrSet(
+        'cached-world-#id#',
+        ()=>queryExecute( '
+            SELECT id, randomNumber
+            FROM World
+            WHERE id = #id#
+        ').getRow( 1 ) ) >    
+    <cfset results.append( qry )>
+</cfloop>
+<cfoutput>#serializeJSON( results )#</cfoutput>

+ 34 - 0
frameworks/CFML/CFML/src/config/CacheBox.cfc

@@ -0,0 +1,34 @@
+component{
+	
+	/**
+	* Configure CacheBox for ColdBox Application Operation
+	*/
+	function configure(){
+		
+		// The CacheBox configuration structure DSL
+		cacheBox = {
+			// LogBox config already in coldbox app, not needed
+			// logBoxConfig = "coldbox.system.web.config.LogBox", 
+			
+			// The defaultCache has an implicit name "default" which is a reserved cache name
+			// It also has a default provider of cachebox which cannot be changed.
+			// All timeouts are in minutes
+			defaultCache = {
+				objectDefaultTimeout = 120, //two hours default
+				objectDefaultLastAccessTimeout = 30, //30 minutes idle time
+				useLastAccessTimeouts = false,
+				reapFrequency = 15,
+				freeMemoryPercentageThreshold = 0,
+				evictionPolicy = "LRU",
+				evictCount = 1,
+				maxObjects = 15000,
+				objectStore = "ConcurrentStore", //guaranteed objects
+				coldboxEnabled = true
+			},
+			
+			// Register all the custom named caches you like here
+			caches = {}		
+		};
+	}	
+
+}

+ 1 - 1
frameworks/CFML/CFML/src/db.cfm

@@ -1,7 +1,7 @@
 <cfsetting enablecfoutputonly=true>
 <cfheader name="Server" value="cfml-lucee">
 <cfheader name="Content-Type" value="application/json">
-<cfquery name="qry" datasource="world">
+<cfquery name="qry">
     SELECT id, randomNumber
     FROM World
     WHERE id = <cfqueryparam value="#randRange( 1, 10000 )#" cfsqltype="integer">

+ 1 - 1
frameworks/CFML/CFML/src/fortunes.cfm

@@ -1,7 +1,7 @@
 <cfsetting enablecfoutputonly=true>
 <cfheader name="Server" value="cfml-lucee">
 <cfheader name="Content-Type" value="text/html; charset=utf-8">
-<cfquery name="qry" datasource="world">
+<cfquery name="qry">
     SELECT id, message
     FROM Fortune
 </cfquery>

+ 1 - 1
frameworks/CFML/CFML/src/queries.cfm

@@ -10,7 +10,7 @@
 <cfheader name="Content-Type" value="application/json">
 <cfset results = []>
 <cfloop from="1" to="#url.queries#" index="i">
-    <cfquery name="qry" datasource="world">
+    <cfquery name="qry">
         SELECT id, randomNumber
         FROM World
         WHERE id = <cfqueryparam value="#randRange( 1, 10000 )#" cfsqltype="integer">

+ 2 - 2
frameworks/CFML/CFML/src/updates.cfm

@@ -10,7 +10,7 @@
 <cfheader name="Content-Type" value="application/json">
 <cfset results = []>
 <cfloop from="1" to="#url.queries#" index="i">
-    <cfquery name="qry" datasource="world">
+    <cfquery name="qry">
         SELECT id, randomNumber
         FROM World
         WHERE id = <cfqueryparam value="#randRange( 1, 10000 )#" cfsqltype="integer">
@@ -19,7 +19,7 @@
 </cfloop>
 
 <cfloop array="#results#" index="i">
-    <cfquery datasource="world">
+    <cfquery>
         update World 
         SET randomNumber = #val( i.randomNumber )#
         where id = #val( i.id )#;

+ 2 - 0
frameworks/CFML/coldbox/benchmark_config.json

@@ -9,6 +9,7 @@
         "fortune_url": "/index.cfm?event=main.fortunes",
         "plaintext_url": "/index.cfm?event=main.plaintext",
         "update_url": "/index.cfm?event=main.updates&queries=",
+        "cached_query_url": "/index.cfm?event=main.cached&count=",
         "port": 8080,
         "approach": "Realistic",
         "classification": "Fullstack",
@@ -32,6 +33,7 @@
         "fortune_url": "/index.cfm?event=main.fortunes",
         "plaintext_url": "/index.cfm?event=main.plaintext",
         "update_url": "/index.cfm?event=main.updates&queries=",
+        "cached_query_url": "/index.cfm?event=main.cached&count=",
         "port": 8080,
         "approach": "Realistic",
         "classification": "Fullstack",

+ 2 - 0
frameworks/CFML/coldbox/coldbox-adobe.dockerfile

@@ -1,5 +1,7 @@
 FROM ortussolutions/commandbox:3.2.1
 
+ENV cfconfig_adminPassword=password
+
 COPY ./src/server-adobe.json /app/server.json
 COPY ./src/.cfconfig.json /app/.cfconfig.json
 COPY ./src/box.json /app/box.json

+ 4 - 0
frameworks/CFML/coldbox/coldbox.dockerfile

@@ -1,5 +1,7 @@
 FROM ortussolutions/commandbox:3.2.1
 
+ENV cfconfig_adminPassword=password
+
 COPY ./src/server-lucee.json /app/server.json
 COPY ./src/.cfconfig.json /app/.cfconfig.json
 COPY ./src/box.json /app/box.json
@@ -8,6 +10,8 @@ RUN box install --verbose --force
 
 RUN ${BUILD_DIR}/util/warmup-server.sh
 
+RUN box cfconfig import from=/app/.cfconfig.json toFormat=luceeWeb
+
 RUN export FINALIZE_STARTUP=true;$BUILD_DIR/run.sh;unset FINALIZE_STARTUP
 
 HEALTHCHECK NONE

+ 141 - 1
frameworks/CFML/coldbox/src/.cfconfig.json

@@ -10,5 +10,145 @@
         }
     },
     "inspectTemplate":"never",
-    "maxCFThreads":"512"
+    "maxCFThreads":"512",
+    "maxTemplateRequests":"512",
+    "adminPassword":"password",
+    "loggers" : {
+        "scheduler":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/scheduler.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "application":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/application.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "requesttimeout":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/requesttimeout.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "exception":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/exception.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "mapping":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/mapping.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "orm":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/orm.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "deploy":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/deploy.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "trace":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/trace.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "memory":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/memory.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "gateway":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/gateway.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "search":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/search.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "rest":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/rest.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "thread":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/thread.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "scope":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/scope.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "datasource":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/datasource.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "remoteclient":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/remoteclient.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        },
+        "mail":{
+            "appender":"resource",
+            "appenderArguments":{
+                "path":"{lucee-config}/logs/mail.log"
+            },
+            "level":"fatal",
+            "layout":"classic"
+        }
+    }
 }

+ 50 - 0
frameworks/CFML/coldbox/src/config/CacheBox.cfc

@@ -0,0 +1,50 @@
+component{
+	
+	/**
+	* Configure CacheBox for ColdBox Application Operation
+	*/
+	function configure(){
+		
+		// The CacheBox configuration structure DSL
+		cacheBox = {
+			// LogBox config already in coldbox app, not needed
+			// logBoxConfig = "coldbox.system.web.config.LogBox", 
+			
+			// The defaultCache has an implicit name "default" which is a reserved cache name
+			// It also has a default provider of cachebox which cannot be changed.
+			// All timeouts are in minutes
+			defaultCache = {
+				objectDefaultTimeout = 120, //two hours default
+				objectDefaultLastAccessTimeout = 30, //30 minutes idle time
+				useLastAccessTimeouts = false,
+				reapFrequency = 15,
+				freeMemoryPercentageThreshold = 0,
+				evictionPolicy = "LRU",
+				evictCount = 1,
+				maxObjects = 15000,
+				objectStore = "ConcurrentStore", //guaranteed objects
+				coldboxEnabled = true
+			},
+			
+			// Register all the custom named caches you like here
+			caches = {
+				// Named cache for all coldbox event and view template caching
+				template = {
+					provider = "coldbox.system.cache.providers.CacheBoxColdBoxProvider",
+					properties = {
+						objectDefaultTimeout = 120,
+						objectDefaultLastAccessTimeout = 30,
+						useLastAccessTimeouts = true,
+						freeMemoryPercentageThreshold = 0,
+						reapFrequency = 5,
+						evictionPolicy = "LRU",
+						evictCount = 2,
+						maxObjects = 300,
+						objectStore = "ConcurrentSoftReferenceStore" //memory sensitive
+					}
+				}		
+			}		
+		};
+	}	
+
+}

+ 14 - 0
frameworks/CFML/coldbox/src/config/Coldbox.cfc

@@ -15,5 +15,19 @@ component {
 		};
 
 	}
+	
+	function afterConfigurationLoad() {
+		var cache = controller.getCacheBox().getCache( 'default' );
+		cfloop( from="1", to="10000", index="local.i" ) {
+			cache.getOrSet(
+				'cached-world-#i#',
+				()=>queryExecute( '
+					SELECT id, randomNumber
+					FROM World
+					WHERE id = #i#
+				').getRow( 1 )
+			);
+		}
+	}
 
 }

+ 26 - 0
frameworks/CFML/coldbox/src/handlers/Main.cfc

@@ -1,4 +1,5 @@
 component extends="coldbox.system.EventHandler" {
+	property name='cache' inject='cachebox:default';
 
 	function prehandler( event ) {
 		event.setHTTPHeader( name="Server", value="cfml-coldbox" )
@@ -84,4 +85,29 @@ component extends="coldbox.system.EventHandler" {
 		event.renderData( data=results, type="json" );
 	}
 
+	function cached( event, rc, prc ) {
+				
+		event.paramValue( 'count', 1 );
+		rc.count = val( rc.count );
+		if( rc.count > 500 ) {
+			rc.count = 500;
+		} else if( rc.count < 1 ) {
+			rc.count = 1;
+		}
+		var results = [];
+		cfloop( from="1", to="#rc.count#", index="local.i" ) {
+			var id = randRange( 1, 10000 );
+			var qry = cache.getOrSet(
+				'cached-world-#local.id#',
+				()=>queryExecute( '
+					SELECT id, randomNumber
+					FROM World
+					WHERE id = #id#
+				').getRow( 1 ) );			
+			results.append( qry );
+		}
+
+		event.renderData( data=results, type="json" );		
+	}
+
 }