gpt4 book ai didi

javascript - Meteor框架免费服务器崩溃

转载 作者:行者123 更新时间:2023-12-03 08:33:26 25 4
gpt4 key购买 nike

嗨,我刚刚学习了 Meteor 并开发了一款多人游戏。出于测试目的,我部署到免费服务器,每天晚上我们和一些 friend 一起玩游戏,通常有 20 个在线人。然而,网站有时会崩溃,没有数据进出。它只是卡住了。我检查了客户端日志和服务器日志,但什么也没有。当我刷新页面时,它卡住在加载模板上。

我使用铁路由器作为加载屏幕:

Router.configure({
layoutTemplate: 'main',
notFoundTemplate: 'notFound',
loadingTemplate: 'loading'
});

Router.route('/loading', {
template : 'loading'
});

Router.route('/', {
template : 'home',
waitOn: function() {
return [Meteor.subscribe('chat'),Meteor.subscribe('games'),Meteor.subscribe('users')];
},
data : function(){
return {
chat : Chat.find({},{sort: {createdAt: 1}}),
games : Games.find({},{sort: {createdAt: -1}}),
users : Meteor.users.find({},{sort : {"status.online":-1}})
}
}
});

我不知道这个问题。有时在主页上卡住,有时在游戏页面上卡住。对于游戏页面,我正在简化我的代码以便您理解。

游戏中有两个关卡:白天和黑夜。它从游戏创建者的点击开始,早晨从倒计时开始。当倒计时结束时,夜晚就会开始相应的倒计时。并且它会继续循环直到游戏结束。早上结束时,游戏会进行一些计算,然后切换到晚上。夜晚也一样。

为了倒计时,我将 setTimeOut() 函数与 Fiber 结合使用。

Meteor.methods({
startGame : function(id){
//some other code here
//....

//set timestamp of the end date
var currentDate = new Date();
console.log("currentDate: "+currentDate);
if(night){ var interval = durationNight;}
else{ var interval = durationMorning;}
console.log("interval: "+interval);
var endDate = currentDate.setSeconds(currentDate.getSeconds() + interval);
console.log("endDate: "+endDate);

Games.update({"_id" : id}, {$set : {"endTime" : endDate}});


endLevelInternal[id] = setTimeout(function () {
// // completed
Fiber(function() {
console.log(id +' countdown completed');

endLevelFlag[id] = true;

if(endLevelFlag[id]){
endLevelFlag[id] = false;
Meteor.call('endLevel', id, function(){
endLevelFlag[id] = true;
});
}
}).run();

}, interval*1000);
},

endLevel : function(){
//some other code here
//...

//
if(!finished){
Meteor.call('startGame', id);
}
}
});

Template.game.events({
'click .startGame' : function(evt, template){
var flag = true;
if(flag){
flag = false;
Meteor.call('startGame', template.data._id, function(){
flag = true;
});
}
}
});

我不确定问题是由于服务器代码还是由于免费服务器(RAM 或 CPU)的限制。

最佳答案

我建议查看 Meteor 日志,或部署在其他已准备好生产的平台上。一种选择是使用 Meteor Up 的 AWS 或 DigitalOcean。

关于javascript - Meteor框架免费服务器崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33270465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com