یه مشکل عجیب زمانی که دارم سرور به صورت کلاسترینگ توسعه میدم

34 views
Skip to first unread message

مهدی پیشگوی

unread,
Aug 5, 2016, 11:40:35 AM8/5/16
to nodejs-fa
سلام  دوستان عزیز. زمانی که سرور به صورت کلاستر نیست قشنگ کار میکنه و مشکلی نداره ولی وقتی که اون رو به کلاستر تغییر میدم دیگه نمیتونم سمت اندروید کانکت بشم و دائما لاگ اتصال به سرور رو میگیرم. و سوکتهام درست کارنمیکنن. مثلا برای لاگین چندین و چند بار باید بزنم تا لاگین شه اون هم تصادفی. معلوم نیست کی این اتفاق لاگین می افته. من کدها رو میزارم ممنون میشم بررسیش کنید



var cluster = require('cluster'), _portSocket = 3000, _portRedis = 6379, _HostRedis = 'localhost';

if (cluster.isMaster) {
var server = require('http').createServer(),
socketIO = require('socket.io').listen(server),
 
redis = require('socket.io-redis');

socketIO.adapter(redis({host: _HostRedis, port: _portRedis}));
var numCPUs = require('os').cpus().length;
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}

cluster.on('exit', function (worker, code, signal) {
if (!worker.suicide) {
cluster.fork();
}
});
}

if (cluster.isWorker) {

var http = require('http');

http.globalAgent.maxSockets = Infinity;

var socket = require('socket.io')(3000),
express = require('express'),
app = express(),
server = require('http').createServer(app),
io = socket.listen(server),
mysql = require('mysql'),
multer = require('multer'),
uuid = require('node-uuid'),
datetime = require('node-datetime'),
moment = require('moment'),
bcrypt = require('bcrypt'),
request = require('request'),
redis = require("redis-node"),
redisIo = require('socket.io-redis'),
email = require("emailjs"),
redisClient = redis.createClient();

var connection =
mysql.createConnection(
{
host : 'localhost',
user : 'root',
password : 'a',
database : 'shoot',
multipleStatements: true
});

socket.adapter(redisIo({host: _HostRedis, port: _portRedis}));

socket.sockets.on('connection', function (socket, pseudo) {

socket.on('login', function (data) {
...
});

});
}


function formatDate(date) {
return moment(date).format('YYYY-MM-DD HH:mm:ss');
}

function login(username, password, callback) {
...
}


Amin Aghabeiki

unread,
Aug 18, 2016, 11:10:43 PM8/18/16
to nodejs-fa
Hi bro , 
I read your code, way you don't use a real time framework like Sails.js ?
it's support ORM , socket connection and ( if you using Android ) it support auto generated REST API.
anyway I'll check your problem to find the Issue , I hope it's can make you work on it. 

PS: sorry for my EN post , I try to type in Persian but the RTL is not work good ! 

Regards


mahdi pishguy

unread,
Aug 19, 2016, 1:16:22 AM8/19/16
to node...@googlegroups.com

Hi, thanks. I can resolve this peoblem by using simple clustering library and work fine now. I dont use your introduces library on project. But i liked to use SOCKETCLUSTER library which as far as i know thats implemented very good fearure for this structure. But it doesnt make rest api. I'm not have to using that if sails can make my necessary fields, please let me to get more information about that. Thanks

Amin Aghabeiki

unread,
Aug 19, 2016, 2:59:38 AM8/19/16
to nodejs-fa
good news ,  just read about Sails at this Link
but simple note aboute Sails : 
* any db support , its use Waterline ORM ( I use this ORM in all of my node js project  around 2-3 years ) inside it ( but you can use it separated ) 
* about scaling  read here
* about socket Server * Client 
and more you can googling 

Regards

Morteza Milani

unread,
Aug 19, 2016, 3:16:58 AM8/19/16
to node...@googlegroups.com

کاش در‌گروه فارسی ند، فارسی صحبت کنیم :)


--
You received this message because you are subscribed to the Google Groups "nodejs-fa" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-fa+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mahdi pishguy

unread,
Aug 19, 2016, 3:50:32 AM8/19/16
to node...@googlegroups.com
​سلام آقای میلانی. بلی حق با شماست. چشم. ;)

Amin Aghabeiki

unread,
Aug 19, 2016, 8:20:34 AM8/19/16
to node...@googlegroups.com

Yep, but the problem comes from RTL !


You received this message because you are subscribed to a topic in the Google Groups "nodejs-fa" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs-fa/P3C3gOyotP0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs-fa+unsubscribe@googlegroups.com.

Amir Saboury

unread,
Aug 19, 2016, 1:54:36 PM8/19/16
to node...@googlegroups.com
سلام،

بنده هم خواهش می‌کنم فارسی بنویسید.
فارسی نوشتن، حتی اگه از «چپ به راست» باشه بهتر از این طور انگلیسی نوشتن هست.


در مورد مشکل socket.io و clustering: کد شما رو یه نگاه اجمالی کردم. شما در قسمت isMaster هم دارید redis رو برای socket.io تنظیم می‌کنید که نیازی به این کار نیست (docs). باقی قسمت‌های کد normal به نظر می‌رسه. احتمالاً‌ مشکل از جای دیگه‌ای باشه. البته کد شما هم ساختارش توی ایمیل بهم ریخته و سخته خوندنش.
خوبه که اگر کدی به گروه می‌فرستیم توی سایت‌هایی که سرویس paste ارائه می‌دن بذاریم و لینکش رو اینجا بذاریم. سایت‌هایی مثل paste.ubuntu.com یا scod.ir .



سپاس،
-- امیر

mahdi pishguy

unread,
Aug 19, 2016, 1:56:55 PM8/19/16
to node...@googlegroups.com
​مشکل رو تقریبا بعد از چند روز ارسال این مطلب درست کردم والان به صورت کلاسترینگ دارم از نود استفاده میکنم. از sticky-socket-cluster استفاده کردم

Amin Aghabeiki

unread,
Aug 19, 2016, 2:32:07 PM8/19/16
to node...@googlegroups.com

دوست عزیز ، این بسیار خوب هست که انقدر به پارسی اهمیت می دین.
ولی به نظر من اگه ، واقعا جمع شدیم راجب نود حرف بزنیم و اطلاعاتمون به اشتراک بزاریم. لطفا یک مقدار از قسمت های سنتی و شاید مشکل دار فرهنگیمون رو دور بریزیم.

در ابتدا خدمتتون گفتم مشکل دارم و نمی تونم تایپ کنم راست به چپ رو.

تک تک اعضای گروه باید بیان نظر کارشناسی بدن که پارسی بهتر از فارسی هست!
لطفا در مورد دانش صحبت کنیم. اگه کسی نود می دونه. مطمعنا انگلیسی بد بنده رو هم می تونه به خونه. و اون قسمتی که بابت نوشتن به انگلیسی رو توضیح دادم رو هم می تونه بخونه.
پس قاعدتا می تونه درک کنه.

با احترام


On Aug 20, 2016 1:56 AM, "mahdi pishguy" <pis...@gmail.com> wrote:
​مشکل رو تقریبا بعد از چند روز ارسال این مطلب درست کردم والان به صورت کلاسترینگ دارم از نود استفاده میکنم. از sticky-socket-cluster استفاده کردم

--
Reply all
Reply to author
Forward
0 new messages