PS C:\Users\loginid> az login A web browser has been opened at https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize. Please continue the login in the web browser. If no web browser is available or if the web browser fails to open, use device code flow with `az login --use-device-code`. [ { "cloudName": "AzureCloud", "homeTenantId": "85cb24e4-0bcf-4767-b44b-39eae544706e", "id": "bd435e85-b401-48c5-90ad-96dbefac1503", "isDefault": true, "managedByTenants": [], "name": "Visual Studio Professional", "state": "Enabled", "tenantId": "85cb24e4-0bcf-4767-b44b-39eae544706e", "user": { "name": "sunny_hll@hotmail.com", "type": "user" } } ]
Az Terraform example
1 2 3 4 5 6 7 8 9 10 11 12 13 14
PS C:\Users\loginid> az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/bd435e85-b401-48c5-90ad-96dbefac1503" Creating 'Contributor' role assignment under scope '/subscriptions/bd435e85-b401-48c5-90ad-96dbefac1503' The output includes credentials that you must protect. Be sure that you do not include these credentials in your code or check the credentials into your source control. For more information, see https://aka.ms/azadsp-cli { "appId": "414b5739-2c30-4cea-adff-d5c8ff1c6470", "displayName": "azure-cli-2022-12-09-06-36-24", "password": "if48Q~Wd6aUHekpKNLrgJWeC3Pr-sstzZHRXfa90", "tenant": "85cb24e4-0bcf-4767-b44b-39eae544706e" }
huangsun@oc-dev:~/helm$ cd gsm/ huangsun@oc-dev:~/helm/gsm$ ls Chart.yaml charts templates values.yaml
# intall release
huangsun@oc-dev:~/helm$ helm install myapp gsm NAME: myapp LAST DEPLOYED: Sun Jun 1 10:07:23 2025 NAMESPACE: optimus STATUS: deployed REVISION: 1 NOTES: 1. Get the application URL by running these commands: export POD_NAME=$(kubectl get pods --namespace optimus -l "app.kubernetes.io/name=gsm,app.kubernetes.io/instance=myapp" -o jsonpath="{.items[0].metadata.name}") export CONTAINER_PORT=$(kubectl get pod --namespace optimus $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") echo"Visit http://127.0.0.1:8080 to use your application" kubectl --namespace optimus port-forward $POD_NAME 8080:$CONTAINER_PORT #查看pod状态 huangsun@oc-dev:~/helm$ k get po NAME READY STATUS RESTARTS AGE hello-node-7556f558d-psbrp 1/1 Running 4 537d myapp-gsm-7f8b95f4-g856s 0/1 Error 3 (29s ago) 50s #查看release状态 huangsun@oc-dev:~/helm$ helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION myapp optimus 1 2025-06-01 10:07:23.835586443 +0000 UTC deployed gsm-0.1.0 1.16.0
Integer calc(Integer x, Integer y, String token){ if(token.equals("+")) return x +y; if (token.equals("-")) return y -x; if(token.equals("*")) return x *y; if (token.equals("/")) return y /x; return0; } }
Integer calc(Integer x, Integer y, String token){ if(token.equals("+")) return x +y; if (token.equals("-")) return y -x; if(token.equals("*")) return x *y; if (token.equals("/")) return y /x; return0; } }
// 单调递减栈 private Stack<Integer> min = newStack<>(); // 原栈 private Stack<Integer> s = newStack<>(); }
/** * Your MinStack object will be instantiated and called as such: * MinStack obj = new MinStack(); * obj.push(val); * obj.pop(); * int param_3 = obj.top(); * int param_4 = obj.getMin(); */
publicNumMatrix(int[][] matrix) { n = matrix.length;//row number; m = matrix[0].length; // col number; sum = newint[n+1][m+1]; // 二维数组前缀和 for(inti=1; i <= n ; i ++){ for(intj=1; j <= m; j++) { sum[i][j] = sum[i - 1][j] + sum[i][j-1] -sum[i-1][j-1]+ matrix[i-1][j-1]; } } } publicintsumRegion(int row1, int col1, int row2, int col2) { row1++; row2++; col1++; col2++; // 索引加一,符合前缀和数组1开头算法。 return sum[row2][col2] - sum[row1-1][col2] - sum[row2][col1-1] + sum[row1-1][col1-1]; }
int sum[][]; int n, m; }
/** * Your NumMatrix object will be instantiated and called as such: * NumMatrix obj = new NumMatrix(matrix); * int param_1 = obj.sumRegion(row1,col1,row2,col2); */
@Override publicintcompareTo(Pair other) { //multiplied to -1 as the author need descending sort order return Integer.valueOf(this.value).compareTo(other.value); } } }
@Override publicintcompareTo(Pair other) { //multiplied to -1 as the author need descending sort order return Integer.valueOf(this.value).compareTo(other.value); } } }
/** * Called by {@link #open()} to obtain the accepting channel. * * @return ServerSocketChannel used to accept connections. * @throws IOException if unable to obtain or configure the server channel */ protected ServerSocketChannel openAcceptChannel()throws IOException { ServerSocketChannelserverChannel=null; if (isInheritChannel()) { Channelchannel= System.inheritedChannel(); if (channel instanceof ServerSocketChannel) serverChannel = (ServerSocketChannel)channel; else LOG.warn("Unable to use System.inheritedChannel() [{}]. Trying a new ServerSocketChannel at {}:{}", channel, getHost(), getPort()); }
// The producer used by the strategies will never // be idle (either produces a task or blocks).
// The normal strategy obtains the produced task, schedules // a new thread to produce more, runs the task and then exits. _selectorManager.execute(_strategy::produce);
// Set started only if we really are started Startstart=newStart(); submit(start); start._started.await(); }
Selector事件的生产者/消费者模式:选择器本身是可以复用的,也就是大量请求创建的大量socketchannel是可以共享一个选择器实例,并且通过selectedKey.channel()获得相应的channel实例。这相较于传统的一个请求一个线程模式提高了线程利用率,避免了大量请求带来的线程池饥饿问题。同时,selector本身的事件也需要有很好的资源复用,否则,生产者产生的大量任务同时也会让消费者线程饥饿造成阻塞。Jetty为了解决这个问题采用了一种新的消费模式: EPC,即 eat what you kill消费者和生产者同线程优先处理模式。
if (LOG.isDebugEnabled()) LOG.debug("updates {}", updates);
if (selector != null) { if (LOG.isDebugEnabled()) LOG.debug("wakeup on updates {}", this); selector.wakeup(); } }
updateKeys(): 处理Selectable实例的updateKey和_keys清理
1 2 3 4 5 6 7 8 9 10 11 12 13 14
privatevoidupdateKeys() { // Do update keys for only previously selected keys. // This will update only those keys whose selection did not cause an // updateKeys update to be submitted. for (SelectionKey key : _keys) { Objectattachment= key.attachment(); if (attachment instanceof Selectable) ((Selectable)attachment).updateKey(); } _keys.clear(); }
privatebooleanselect() { try { Selectorselector= _selector; if (selector != null) { if (LOG.isDebugEnabled()) LOG.debug("Selector {} waiting with {} keys", selector, selector.keys().size()); //阻塞等待select()返回 intselected= ManagedSelector.this.select(selector); // The selector may have been recreated. selector = _selector; if (selector != null) { if (LOG.isDebugEnabled()) LOG.debug("Selector {} woken up from select, {}/{}/{} selected", selector, selected, selector.selectedKeys().size(), selector.keys().size());
publicbooleanhandle() { if (LOG.isDebugEnabled()) LOG.debug("handle {} {} ", _request.getHttpURI(), this);
HttpChannelState.Actionaction= _state.handling();
// Loop here to handle async request redispatches. // The loop is controlled by the call to async.unhandle in the // finally block below. Unhandle will return false only if an async dispatch has // already happened when unhandle is called. loop: while (!getServer().isStopped()) { try { if (LOG.isDebugEnabled()) LOG.debug("action {} {}", action, this);
switch (action) { case TERMINATED: onCompleted(); break loop;
case WAIT: // break loop without calling unhandle break loop;
case DISPATCH: { if (!_request.hasMetaData()) thrownewIllegalStateException("state=" + _state);
dispatch(DispatcherType.REQUEST, () -> { for (HttpConfiguration.Customizer customizer : _configuration.getCustomizers()) { customizer.customize(getConnector(), _configuration, _request); if (_request.isHandled()) return; } getServer().handle(HttpChannel.this); });
break; }
case ASYNC_DISPATCH: { dispatch(DispatcherType.ASYNC, () -> getServer().handleAsync(this)); break; }
case ASYNC_TIMEOUT: _state.onTimeout(); break;
case SEND_ERROR: { try { // Get ready to send an error response _response.resetContent();
// the following is needed as you cannot trust the response code and reason // as those could have been modified after calling sendError Integercode= (Integer)_request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); if (code == null) code = HttpStatus.INTERNAL_SERVER_ERROR_500; _response.setStatus(code);
// The handling of the original dispatch failed and we are now going to either generate // and error response ourselves or dispatch for an error page. If there is content left over // from the failed dispatch, then we try to consume it here and if we fail we add a // Connection:close. This can't be deferred to COMPLETE as the response will be committed // by then. ensureConsumeAllOrNotPersistent();
// If we can't have a body, then create a minimal error response. if (HttpStatus.hasNoBody(_response.getStatus()) || errorHandler == null || !errorHandler.errorPageForMethod(_request.getMethod())) { sendResponseAndComplete(); break; }
dispatch(DispatcherType.ERROR, () -> { errorHandler.handle(null, _request, _request, _response); _request.setHandled(true); }); } catch (Throwable x) { if (LOG.isDebugEnabled()) LOG.debug("Could not perform ERROR dispatch, aborting", x); if (_state.isResponseCommitted()) abort(x); else { try { _response.resetContent(); sendResponseAndComplete(); } catch (Throwable t) { if (x != t) x.addSuppressed(t); abort(x); } } } finally { // clean up the context that was set in Response.sendError _request.removeAttribute(ErrorHandler.ERROR_CONTEXT); } break; }
case ASYNC_ERROR: { throw _state.getAsyncContextEvent().getThrowable(); }
case READ_CALLBACK: { ContextHandlerhandler= _state.getContextHandler(); if (handler != null) handler.handle(_request, _request.getHttpInput()); else _request.getHttpInput().run(); break; }
case WRITE_CALLBACK: { ContextHandlerhandler= _state.getContextHandler(); if (handler != null) handler.handle(_request, _response.getHttpOutput()); else _response.getHttpOutput().run(); break; }
case COMPLETE: { if (!_response.isCommitted()) { if (!_request.isHandled() && !_response.getHttpOutput().isClosed()) { // The request was not actually handled _response.sendError(HttpStatus.NOT_FOUND_404); break; }
// Indicate Connection:close if we can't consume all. if (_response.getStatus() >= 200) ensureConsumeAllOrNotPersistent(); }
// RFC 7230, section 3.3. if (!_request.isHead() && _response.getStatus() != HttpStatus.NOT_MODIFIED_304 && !_response.isContentComplete(_response.getHttpOutput().getWritten())) { if (sendErrorOrAbort("Insufficient content written")) break; }
// If send error is called we need to break. if (checkAndPrepareUpgrade()) break; // Set a close callback on the HttpOutput to make it an async callback _response.completeOutput(Callback.from(NON_BLOCKING, () -> _state.completed(null), _state::completed));