Class: Norikra::CLI
- Inherits:
-
Thor
- Object
- Thor
- Norikra::CLI
- Defined in:
- lib/norikra/cli.rb
Constant Summary collapse
- JVM_OPTIONS =
JVM defaults w/ ConcurrentGC:
java -XX:+UseConcMarkSweepGC -XX:+PrintFlagsFinal -version (jruby does not modify flags) CMSIncrementalMode: not recommended in Java8 CMSInitiatingOccupancyFraction: CMS threshold CMSInitiatingOccupancyFraction = 100 - MinHeapFreeRatio + CMSTriggerRatio * MinHeapFreeRatio / 100 default: MinHeapFreeRatio=40 CMSTriggerRatio=80 -> CMSInitiatingOccupancyFraction=92 NewRatio=7 (New:Old = 1:7) InitialSurvivorRatio=8 MinSurvivorRatio=3 SurvivorRatio=8 (Eden:Survivor0:survivor1 = 8:1:1) MaxTenuringThreshold=4 TargetSurvivorRatio=50 (InitialTenuringThreshold=7 is for Parallel GC/UseAdaptiveSizePolicy) SoftRefLRUPolicyMSPerMB=1000 ( gc_interval > free_heap * ms_per_mb : clear softref ) [ '-XX:-UseGCOverheadLimit', '-XX:+UseConcMarkSweepGC', '-XX:+UseCompressedOops', '-XX:CMSInitiatingOccupancyFraction=70', '-XX:+UseCMSInitiatingOccupancyOnly', '-XX:NewRatio=1', '-XX:SurvivorRatio=2', '-XX:MaxTenuringThreshold=15', '-XX:TargetSurvivorRatio=80', '-XX:SoftRefLRUPolicyMSPerMB=200', ]
- JVM_GC_OPTIONS =
[ '-verbose:gc', '-XX:+PrintGCDetails', '-XX:+PrintGCDateStamps', '-XX:+HeapDumpOnOutOfMemoryError', ]
Instance Method Summary collapse
Instance Method Details
#serverproc ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/norikra/cli.rb', line 193 def serverproc conf = {} if [:daemonize] conf[:daemonize] = {outfile: [:outfile]} end ### stat file conf[:stats] = { path: [:stats], secondary_path: [:'stats-secondary'], suppress: [:'suppress-dump-stat'], interval: [:'dump-stat-interval'], } ### shut off mode conf[:shutoff] = { enabled: [:shutoff], threshold: [:'shutoff-threshold'], interval: [:'shutoff-check-interval'], } ### threads predefined_selecteds = [:micro, :small, :middle, :large].select{|sym| [sym]} if predefined_selecteds.size > 1 raise Norikra::ConfigurationError, "one of micro/small/middle/large should be specified" end conf[:thread] = { predefined: predefined_selecteds.first, micro: [:micro], small: [:small], middle: [:middle], large: [:large], engine: {inbound:{}, outbound:{}, route_exec:{}, timer_exec:{}}, rpc: {}, web: {}, } [:inbound, :outbound, :route_exec, :timer_exec].each do |sym| opt_sym = case sym when :route_exec then :route when :timer_exec then :timer else sym end conf[:thread][:engine][sym][:threads] = [:"#{opt_sym}-threads"] if [:"#{opt_sym}-threads"] conf[:thread][:engine][sym][:capacity] = [:"#{opt_sym}-thread-capacity"] if [:"#{opt_sym}-thread-capacity"] end conf[:thread][:rpc][:threads] = [:'rpc-threads'] if [:'rpc-threads'] conf[:thread][:web][:threads] = [:'web-threads'] if [:'web-threads'] ### logs loglevel = case when [:'more-verbose'] then 'TRACE' when [:verbose] then 'DEBUG' when [:quiet] then 'WARN' when [:'more-quiet'] then 'ERROR' else nil # for default (assumed as 'INFO') end conf[:log] = { level: loglevel, dir: [:logdir], filesize: [:'log-filesize'], backups: [:'log-backups'], bufferlines: [:'log-buffer-lines'], } conf[:log4j_properties_path] = [:'log4j-properties-path'] = { host: [:host], port: [:port], ui_port: [:'ui-port'], ui_context_path: [:'ui-context-path'], } server = Norikra::Server.new( , conf ) server.run server.shutdown end |
#start(*optargs) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/norikra/cli.rb', line 128 def start(*optargs) if [:help] invoke :help, ["start"] return end ARGV.shift # shift head "start" argv = ["serverproc"] = ['-J-server'] unless [:'bare-jvm'] += JVM_OPTIONS.map{|opt| '-J' + opt } end if [:'gc-log'] += JVM_GC_OPTIONS.map{|opt| '-J' + opt } .push "-J-Xloggc:#{[:'gc-log']}" end ARGV.each do |arg| if arg =~ /^-X(.+)$/ .push('-J-X' + $1) elsif arg =~ /^-verbose:gc$/ .push('-J-verbose:gc') elsif arg =~ /^-javaagent:(.+)$/ .push('-J-javaagent:' + $1) else argv.push(arg) end end # norikra/lib/norikra binpath = File.(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'norikra')) jruby_path = RbConfig.ruby args = + [binpath] + argv if [:daemonize] unless [:logdir] puts "'logdir' must be specified for '--daemonize'." exit(1) end ## need to close/reopen STDIN/STDOUT/STDERR in child process outfile = [:outfile] || File.join([:logdir], '/norikra.out') File.open(outfile, 'w'){|file| file.write 'write test on parent process'} pidfile = File.open([:pidfile], 'w') pid = spawn(jruby_path, *args, pgroup: 0) pidfile.write(pid.to_s) pidfile.close waiting_child = true while waiting_child && sleep(1) out = File.open(outfile){|f| f.read} waiting_child = false if out =~ /working on #{pid}/ end Process.detach(pid) else exec(jruby_path, *args) end end |
#stop ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/norikra/cli.rb', line 268 def stop unless test(?r,[:pidfile]) puts "Cannot find pidfile at #{[:pidfile]}" exit(1) end pid = File.open([:pidfile]){|f| f.read}.to_i timeout = Time.now + [:timeout] waiting = true Process.kill(:TERM, pid) begin while waiting && Time.now < timeout sleep(0.5) status = Process.waitpid(pid, Process::WNOHANG) if status waiting = false end end rescue Errno::ECHILD waiting = false end if waiting puts "Faild to stop Norikra server #{pid}" exit(1) else File.unlink([:pidfile]) end end |