docker中的多个nodejs worker(Multiple nodejs workers in docker)
我是docker和生产nodejs web应用程序的新手。 但是,经过一些阅读后我确定了一个好的设置:
- nginx容器提供静态文件,ssl,代理nodejs请求
- nodejs容器
- postgesql容器
但是,我现在正试图解决可扩展性问题。 看你可以在nginx配置中定义多个
proxy_pass
语句,你能不能启动一个重复的nodejs容器(完全相同但暴露不同的端口)并有效地“加载平衡”你的web应用程序? 这是一个很好的建筑吗?此外,此效果数据库将如何写入? 我需要专门针对架构的竞争条件吗? 任何指导将不胜感激。
I'm very new to docker and productionizing nodejs web apps. However, after some reading I've determined that a good setup would be:
- nginx container serving static files, ssl, proxying nodejs requests
- nodejs container
- postgesql container
However, I'm now trying to tackle scalability. Seeing as you can define multiple
proxy_pass
statements in an nginx config, could you not spin up a duplicate nodejs container (exactly the same but exposing a different port) and effectively "load balance" your web app? Is it a good architecture?Also, how would this effect database writes? Are there race conditions I need to specifically architecture for? Any guidance would be appreciated.
原文:https://stackoverflow.com/questions/33088671
最满意答案
在viewDidLoad之外声明您的locationManager ivar。 它在viewDidLoad完成后被释放,因为没有任何强引用。 您可能也应该只在用户授予访问权限后才开始扫描。
var locationManager:CLLocationManager! override func viewDidLoad() { super.viewDidLoad() locationManager = CLLocationManager() locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyBest let authorizationStatus = CLLocationManager.authorizationStatus() if (authorizationStatus == CLAuthorizationStatus.NotDetermined) { locationManager.requestWhenInUseAuthorization() } else if (authorizationStatus == CLAuthorizationStatus.AuthorizedWhenInUse) { locationManager.startUpdatingLocation() } } func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) { if (status == CLAuthorizationStatus.AuthorizedWhenInUse) { locationManager.startUpdatingLocation() }
}
Declare your locationManager ivar outside of viewDidLoad. It is being deallocated after viewDidLoad completes because nothing has a strong reference to it. You should probably also only start scanning after your user has granted access.
var locationManager:CLLocationManager! override func viewDidLoad() { super.viewDidLoad() locationManager = CLLocationManager() locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyBest let authorizationStatus = CLLocationManager.authorizationStatus() if (authorizationStatus == CLAuthorizationStatus.NotDetermined) { locationManager.requestWhenInUseAuthorization() } else if (authorizationStatus == CLAuthorizationStatus.AuthorizedWhenInUse) { locationManager.startUpdatingLocation() } } func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) { if (status == CLAuthorizationStatus.AuthorizedWhenInUse) { locationManager.startUpdatingLocation() }
}
相关问答
更多-
在viewDidLoad之外声明您的locationManager ivar。 它在viewDidLoad完成后被释放,因为没有任何强引用。 您可能也应该只在用户授予访问权限后才开始扫描。 var locationManager:CLLocationManager! override func viewDidLoad() { super.viewDidLoad() locationManager = CLLocationManager() locationManager.delegate = ...
-
虽然很难跟踪,但是解决方案很简单。 通过多次尝试和错误,我发现当您第一次尝试访问应用程序中的任何位置服务时,当位置访问对话框弹出时,如果CLLocationManager对象被释放,对话框将自动消失(没有任何用户交互)在用户响应对话框之前。 我在我的viewDidLoad方法中创建一个CLLocationManager实例。 由于这是该方法的本地实例,所以在方法完成执行后,该实例由ARC发布。 一旦实例被释放,对话框就消失了。 解决方案很简单。 将CLLocationManager实例从方法级变量更改为类级 ...
-
正如您已经注意到的,尝试在iOS上使用Core Bluetooth读取加密特性会触发绑定过程。 核心蓝牙不支持Just Works配对,需要绑定。 只支持密钥配对。 你基本上有两个选择: 删除加密要求 接受将显示配对对话框并提供固定PIN码或带外机制(例如设备上的贴纸) As you have noted an attempt to read an encrypted characteristic using Core Bluetooth on iOS triggers the bonding proces ...
-
首先,您需要在info.plist文件中添加NSLocationWhenInUseUsageDescription或NSLocationAlwaysUsageDescription (如果您想在后台使用)。 看到下面的图片: 接下来,在swift文件中,您需要在viewDidLoad()方法中调用locationManager.requestWhenInUseAuthorization()或locationManager.requestAlwaysAuthorization() 。 最后,您可以在locat ...
-
我解决了将问题添加到tabbarViewController视图的问题: [self.tabBarController.view addSubview:overlay]; I solved the problem adding the overlay to the tabbarViewController's view: [self.tabBarController.view addSubview:overlay];
-
requestWhen在iOS 8中使用授权并等待用户响应(requestWhenInUseAuthorization in iOS 8 and wait until user responds)[2023-02-25]
使用委托方法locationManager:didChangeAuthorizationStatus:在用户允许或不允许位置请求时运行您的代码。 Use the delegate method locationManager:didChangeAuthorizationStatus: to run your code when the user allows or disallows the location request. -
“附近消息”中的策略是仅当iOS需要某些东西(例如麦克风或背景BLE)的许可时才要求获得许可。 在你的情况下,你只在前台使用BLE,并且这种模式不需要iOS权限,所以Nearby不要求权限。 The policy in Nearby Messages is to ask for permission only when iOS requires permission for something (such as for microphone or background BLE). In your case, ...
-
您的locationManager变量不会超出其定义范围(代码片段所在的函数),因此在用户可以响应对话框之前将其解除分配。 如果你将let locationManager = CLLocationManager()移动到一个类变量,它应该坚持下去。 Your locationManager variable won't live beyond the scope of its definition (the function where that snippet of code lives), so it ...
-
如果已授予授权,即使您调用该方法,iOS也不会向用户重新显示该对话框。 如果用户拒绝授权或尚未应答,则再次调用该方法将再次向用户显示对话框。 为了检查是否已授予授权,您可以像这样检查getAuthorizationStatus() : cordova.plugins.locationManager.getAuthorizationStatus() .then(function(authorized){ ... }); If authorization has already been gr ...
-
取一个bool值。 它应该是第一次是假的。 然后用这个替换你的代码。 -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { NSLog(@"Running"); CLLocation *newLocation = [locations lastObject]; [manager stopUpdatingLocation]; CLGeocod ...