feat enable faster load mode
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
880065495e
commit
148f6c28c4
@ -8,10 +8,6 @@
|
||||
"command": {
|
||||
"run": {
|
||||
"stream": true
|
||||
},
|
||||
"publish": {
|
||||
"access": "public",
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
35
packages/common/src/version.ts
Normal file
35
packages/common/src/version.ts
Normal file
@ -0,0 +1,35 @@
|
||||
export type Version = [string, string, string]
|
||||
|
||||
export class VersionUtils {
|
||||
static isEqual(version: string, targetVersion: string): boolean {
|
||||
return version == targetVersion
|
||||
}
|
||||
static isGreaterOrEqual(version: string, targetVersion: string): boolean {
|
||||
const v1 = parseVersion(version)
|
||||
const v2 = parseVersion(targetVersion)
|
||||
|
||||
return (
|
||||
v1[0] > v2[0] ||
|
||||
(v1[0] === v2[0] && v1[1] > v2[1]) ||
|
||||
(v1[0] === v2[0] && v1[1] === v2[1] && v1[2] >= v2[2])
|
||||
)
|
||||
}
|
||||
static isGreater(version: string, targetVersion: string): boolean {
|
||||
const v1 = parseVersion(version)
|
||||
const v2 = parseVersion(targetVersion)
|
||||
|
||||
return (
|
||||
v1[0] > v2[0] ||
|
||||
(v1[0] === v2[0] && v1[1] > v2[1]) ||
|
||||
(v1[0] === v2[0] && v1[1] === v2[1] && v1[2] > v2[2])
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function parseVersion(version: string = ""): Version {
|
||||
const v: Version = ['0', '0', '0']
|
||||
|
||||
version.split(".").forEach((value, i) => (v[i] = value))
|
||||
|
||||
return v
|
||||
}
|
@ -102,8 +102,8 @@ export const MavenDepend = (groupId: string, artifactId: string, version: string
|
||||
const loadedMavenDepend = new Set<string>()
|
||||
|
||||
export function loadMavenDepend(groupId: string, artifactId: string, version: string, recursion = false) {
|
||||
try {
|
||||
const key = `${groupId}:${artifactId}:${version}`
|
||||
try {
|
||||
if (loadedMavenDepend.has(key)) { return }
|
||||
console.info('loading maven dependency', key)
|
||||
let [pom, _] = base.loadMavenDepend(groupId, artifactId, version)
|
||||
@ -137,7 +137,7 @@ export function loadMavenDepend(groupId: string, artifactId: string, version: st
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.warn('attachMavenDepend failed. Error: ' + error)
|
||||
console.warn('load maven dependency', key, 'failed. Error:', error)
|
||||
if (global.debug) {
|
||||
console.ex(error)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ console.i18n("ms.core.ioc.completed", { scope: global.scope, time: (Date.now() -
|
||||
import * as yaml from 'js-yaml'
|
||||
import http from '@ccms/common/dist/http'
|
||||
import * as fs from '@ccms/common/dist/fs'
|
||||
import { VersionUtils } from '@ccms/common/dist/version'
|
||||
|
||||
const UUID = Java.type('java.util.UUID')
|
||||
|
||||
@ -25,6 +26,11 @@ class MiaoScriptCore {
|
||||
this.loadServerConsole()
|
||||
this.loadPlugins()
|
||||
process.emit('core.after.enable')
|
||||
console.i18n("ms.core.engine.completed", {
|
||||
loader: base.version,
|
||||
version: 'v' + global.ScriptEngineVersion,
|
||||
time: (Date.now() - global.ScriptEngineStartTime) / 1000
|
||||
})
|
||||
return () => this.disable()
|
||||
}
|
||||
|
||||
@ -123,13 +129,7 @@ function loadMiaoScriptConfig() {
|
||||
global.ScriptSlowExecuteTime = global.ScriptEngineConfig.slow_execute || 50
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
process.emit('core.before.initialize')
|
||||
loadMiaoScriptConfig()
|
||||
global.ScriptEngineVersion = require('../package.json').version
|
||||
global.setGlobal('loadCoreScript', loadCoreScript)
|
||||
loadCoreScript('initialize')
|
||||
try {
|
||||
function createCore() {
|
||||
let corePackageStartTime = new Date().getTime()
|
||||
container.bind(ContainerInstance).toConstantValue(container)
|
||||
container.bind(plugin.PluginInstance).toConstantValue(base.getInstance())
|
||||
@ -150,23 +150,32 @@ function initialize() {
|
||||
container.load(buildProviderModule())
|
||||
console.i18n("ms.core.package.completed", { scope: global.scope, type, time: (Date.now() - corePackageStartTime) / 1000 })
|
||||
process.emit('core.after.package.initialize')
|
||||
return container.get<MiaoScriptCore>(MiaoScriptCore)
|
||||
}
|
||||
|
||||
let disable = container.get<MiaoScriptCore>(MiaoScriptCore).enable()
|
||||
console.i18n("ms.core.engine.completed", {
|
||||
loader: base.version,
|
||||
version: 'v' + global.ScriptEngineVersion,
|
||||
time: (Date.now() - global.ScriptEngineStartTime) / 1000
|
||||
})
|
||||
process.emit('core.after.initialize')
|
||||
return disable
|
||||
function initialize() {
|
||||
process.emit('core.before.initialize')
|
||||
loadMiaoScriptConfig()
|
||||
global.ScriptEngineVersion = require('../package.json').version
|
||||
global.setGlobal('loadCoreScript', loadCoreScript)
|
||||
loadCoreScript('initialize')
|
||||
try {
|
||||
let core = createCore()
|
||||
if (VersionUtils.isGreaterOrEqual(base.version, '0.22.0')) { return core }
|
||||
return core.enable()
|
||||
} catch (error: any) {
|
||||
if (console.console) {
|
||||
console.i18n("ms.core.initialize.error", { error })
|
||||
console.i18n("core.initialize.error", { error })
|
||||
console.ex(error)
|
||||
} else {
|
||||
error.printStackTrace()
|
||||
}
|
||||
return () => console.i18n('ms.core.engine.disable.abnormal')
|
||||
process.emit('core.initialize.error')
|
||||
return {
|
||||
enable: () => console.i18n('ms.core.engine.disable.abnormal')
|
||||
}
|
||||
} finally {
|
||||
process.emit('core.after.initialize')
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,10 @@ declare global {
|
||||
scope: string
|
||||
logger: any
|
||||
debug: boolean
|
||||
level: string
|
||||
/**
|
||||
* 引擎日志等级
|
||||
*/
|
||||
ScriptEngineLoggerLevel: string
|
||||
/**
|
||||
* 引擎配置
|
||||
*/
|
||||
|
@ -14,3 +14,4 @@ global.setGlobal('Proxy', require('./proxy').Proxy)
|
||||
global.setGlobal('XMLHttpRequest', require('./xml-http-request').XMLHttpRequest)
|
||||
global.setGlobal('Blob', require('blob-polyfill').Blob)
|
||||
console.i18n("ms.polyfill.completed", { time: (new Date().getTime() - polyfillStartTime) / 1000 })
|
||||
export default true
|
||||
|
@ -15,7 +15,7 @@ const DelayQueue = Java.type('java.util.concurrent.DelayQueue')
|
||||
const JavaScriptTask = Java.type(base.getJavaScriptTaskClass().name)
|
||||
|
||||
const threadCount = new AtomicInteger(0)
|
||||
const threadGroup = new ThreadGroup("@ccms/ployfill-micro-task")
|
||||
const threadGroup = new ThreadGroup("@ccms/micro-task")
|
||||
const microTaskPool = new ThreadPoolExecutor(
|
||||
100, 200, 60, TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue(300),
|
||||
@ -76,16 +76,16 @@ class Process extends EventEmitter {
|
||||
class EventLoop {
|
||||
private eventLoopMainThread = undefined
|
||||
private eventLoopTaskQueue = new DelayQueue()
|
||||
private taskExecTimeout = 3
|
||||
private taskExecuteTimeout = 3000
|
||||
private fixedThreadPool = undefined
|
||||
|
||||
constructor() {
|
||||
this.taskExecTimeout = parseInt(process.env.MS_NODE_EVENT_LOOP_TIMEOUT) || 3
|
||||
this.taskExecuteTimeout = parseInt(process.env.MS_TASK_EXECUTE_TIMEOUT) || 3000
|
||||
this.fixedThreadPool = new ThreadPoolExecutor(
|
||||
1, 1, 0, TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue(300),
|
||||
new LinkedBlockingQueue(500),
|
||||
new ThreadFactory((run: any) => {
|
||||
let thread = new Thread(run, "@ccms/node-shim/event-loop-exec")
|
||||
let thread = new Thread(run, "@ccms/event-loop")
|
||||
thread.setDaemon(true)
|
||||
return thread
|
||||
}))
|
||||
@ -115,7 +115,7 @@ class EventLoop {
|
||||
this.intervalTasks = undefined
|
||||
this.eventLoopMainThread = undefined
|
||||
}
|
||||
}, "@ccms/node-shim/event-loop")
|
||||
}, "@ccms/event-loop")
|
||||
this.eventLoopMainThread.setDaemon(true)
|
||||
process.on('exit', () => {
|
||||
this.eventLoopMainThread.interrupt()
|
||||
@ -137,7 +137,9 @@ class EventLoop {
|
||||
if (!callback) {
|
||||
throw new Error(`task ${name} callback function can't be null!`)
|
||||
}
|
||||
if (this.fixedThreadPool.isShutdown()) { return console.warn(`FixedThreadPool isTerminated! ignore Task ${name}!`) }
|
||||
if (this.fixedThreadPool.isShutdown()) {
|
||||
return console.warn(`FixedThreadPool isTerminated! ignore Task ${name}!`)
|
||||
}
|
||||
try {
|
||||
this.fixedThreadPool.submit(new Callable({
|
||||
call: () => {
|
||||
@ -153,13 +155,13 @@ class EventLoop {
|
||||
}
|
||||
}
|
||||
}
|
||||
})).get(this.taskExecTimeout, TimeUnit.SECONDS)
|
||||
})).get(this.taskExecuteTimeout, TimeUnit.MILLISECONDS)
|
||||
} catch (error: any) {
|
||||
if (error instanceof InterruptedException) {
|
||||
return console.warn(`FixedThreadPool isInterrupted exit! Task ${name} exec exit!`)
|
||||
}
|
||||
if (error instanceof TimeoutException) {
|
||||
return console.warn(`Task ${name} => ${callback} exec time greater than ${this.taskExecTimeout}s!`)
|
||||
return console.warn(`Task ${name} => ${callback} exec time greater than ${this.taskExecuteTimeout}s!`)
|
||||
}
|
||||
throw error.getCause && error.getCause() || error
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user